packages feed

keiro-dsl-0.10.0.0: test/conformance-coldstart/Generated/Billing/Nominals/Internal.hs

-- @generated by keiro-dsl 0.9.0.0 (language keiro-dsl 4) from context billing generated nominal ID internals; do not edit.
module Generated.Billing.Nominals.Internal
  ( CustomerId
  , parseCustomerId
  , mkCustomerId
  , customerIdText
  , unsafeCustomerIdFromLegacyText
  , SubscriptionId
  , parseSubscriptionId
  , mkSubscriptionId
  , subscriptionIdText
  , unsafeSubscriptionIdFromLegacyText
  ) where

import Data.Aeson (FromJSON (..), ToJSON (..), withText)
import Data.Text (Text)
import Data.Text qualified as T
import GHC.Generics (Generic)
import Keiro.Codec.IdDomain (typeIdV7Domain, validateIdDomainText)

newtype CustomerId = CustomerId Text
  deriving stock (Generic, Eq, Ord, Show)

instance ToJSON CustomerId where
  toJSON = toJSON . customerIdText

instance FromJSON CustomerId where
  parseJSON = withText "CustomerId" (either (fail . T.unpack) pure . parseCustomerId)

parseCustomerId :: Text -> Either Text CustomerId
parseCustomerId input = case validateIdDomainText (typeIdV7Domain "cust") input of
  Left reason -> Left (T.pack (show reason))
  Right () -> Right (CustomerId input)

mkCustomerId :: Text -> Either Text CustomerId
mkCustomerId = parseCustomerId

customerIdText :: CustomerId -> Text
customerIdText (CustomerId value) = value

unsafeCustomerIdFromLegacyText :: Text -> CustomerId
unsafeCustomerIdFromLegacyText = CustomerId

newtype SubscriptionId = SubscriptionId Text
  deriving stock (Generic, Eq, Ord, Show)

instance ToJSON SubscriptionId where
  toJSON = toJSON . subscriptionIdText

instance FromJSON SubscriptionId where
  parseJSON = withText "SubscriptionId" (either (fail . T.unpack) pure . parseSubscriptionId)

parseSubscriptionId :: Text -> Either Text SubscriptionId
parseSubscriptionId input = case validateIdDomainText (typeIdV7Domain "sub") input of
  Left reason -> Left (T.pack (show reason))
  Right () -> Right (SubscriptionId input)

mkSubscriptionId :: Text -> Either Text SubscriptionId
mkSubscriptionId = parseSubscriptionId

subscriptionIdText :: SubscriptionId -> Text
subscriptionIdText (SubscriptionId value) = value

unsafeSubscriptionIdFromLegacyText :: Text -> SubscriptionId
unsafeSubscriptionIdFromLegacyText = SubscriptionId