keiro-dsl-0.18.0.0: test/conformance-id-admission-domains/Generated/IdAdmissionDomains/Nominals/Internal.hs
-- @generated by keiro-dsl 0.18.0.0 (language keiro-dsl 6) from context id-admission-domains generated nominal ID internals; do not edit.
module Generated.IdAdmissionDomains.Nominals.Internal
( LegacyId
, parseLegacyId
, mkLegacyId
, legacyIdText
, unsafeLegacyIdFromLegacyText
) where
import Data.Aeson (FromJSON (..), ToJSON (..), withText)
import Data.Text (Text)
import Data.Text qualified as T
import GHC.Generics (Generic)
import Keiki.Shape (CanonicalTypeName)
import Keiro.Codec.IdDomain (typeIdV5OrV7Domain, validateIdDomainText)
newtype LegacyId = LegacyId Text
deriving stock (Generic, Eq, Ord, Show)
instance CanonicalTypeName LegacyId
instance ToJSON LegacyId where
toJSON = toJSON . legacyIdText
instance FromJSON LegacyId where
parseJSON = withText "LegacyId" (either (fail . T.unpack) pure . parseLegacyId)
parseLegacyId :: Text -> Either Text LegacyId
parseLegacyId input = case validateIdDomainText (typeIdV5OrV7Domain "legacy") input of
Left reason -> Left (T.pack (show reason))
Right () -> Right (LegacyId input)
mkLegacyId :: Text -> Either Text LegacyId
mkLegacyId = parseLegacyId
legacyIdText :: LegacyId -> Text
legacyIdText (LegacyId value) = value
unsafeLegacyIdFromLegacyText :: Text -> LegacyId
unsafeLegacyIdFromLegacyText = LegacyId