-- | PolicyId

module Blockfrost.Types.Shared.PolicyId
  where

import Data.Aeson (FromJSON, ToJSON)
import Data.String (IsString (..))
import Data.Text (Text)
import qualified Data.Text
import GHC.Generics
import Servant.API (Capture, FromHttpApiData (..), ToHttpApiData (..))
import Servant.Docs (DocCapture (..), ToCapture (..), ToSample (..), samples)

-- | Minting policy Id
newtype PolicyId = PolicyId Text
  deriving stock (PolicyId -> PolicyId -> Bool
(PolicyId -> PolicyId -> Bool)
-> (PolicyId -> PolicyId -> Bool) -> Eq PolicyId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PolicyId -> PolicyId -> Bool
== :: PolicyId -> PolicyId -> Bool
$c/= :: PolicyId -> PolicyId -> Bool
/= :: PolicyId -> PolicyId -> Bool
Eq, Int -> PolicyId -> ShowS
[PolicyId] -> ShowS
PolicyId -> String
(Int -> PolicyId -> ShowS)
-> (PolicyId -> String) -> ([PolicyId] -> ShowS) -> Show PolicyId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PolicyId -> ShowS
showsPrec :: Int -> PolicyId -> ShowS
$cshow :: PolicyId -> String
show :: PolicyId -> String
$cshowList :: [PolicyId] -> ShowS
showList :: [PolicyId] -> ShowS
Show, (forall x. PolicyId -> Rep PolicyId x)
-> (forall x. Rep PolicyId x -> PolicyId) -> Generic PolicyId
forall x. Rep PolicyId x -> PolicyId
forall x. PolicyId -> Rep PolicyId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PolicyId -> Rep PolicyId x
from :: forall x. PolicyId -> Rep PolicyId x
$cto :: forall x. Rep PolicyId x -> PolicyId
to :: forall x. Rep PolicyId x -> PolicyId
Generic)
  deriving newtype (Text -> Either Text PolicyId
ByteString -> Either Text PolicyId
(Text -> Either Text PolicyId)
-> (ByteString -> Either Text PolicyId)
-> (Text -> Either Text PolicyId)
-> FromHttpApiData PolicyId
forall a.
(Text -> Either Text a)
-> (ByteString -> Either Text a)
-> (Text -> Either Text a)
-> FromHttpApiData a
$cparseUrlPiece :: Text -> Either Text PolicyId
parseUrlPiece :: Text -> Either Text PolicyId
$cparseHeader :: ByteString -> Either Text PolicyId
parseHeader :: ByteString -> Either Text PolicyId
$cparseQueryParam :: Text -> Either Text PolicyId
parseQueryParam :: Text -> Either Text PolicyId
FromHttpApiData, PolicyId -> Text
PolicyId -> ByteString
PolicyId -> Builder
(PolicyId -> Text)
-> (PolicyId -> Builder)
-> (PolicyId -> ByteString)
-> (PolicyId -> Text)
-> (PolicyId -> Builder)
-> ToHttpApiData PolicyId
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> (a -> Builder)
-> ToHttpApiData a
$ctoUrlPiece :: PolicyId -> Text
toUrlPiece :: PolicyId -> Text
$ctoEncodedUrlPiece :: PolicyId -> Builder
toEncodedUrlPiece :: PolicyId -> Builder
$ctoHeader :: PolicyId -> ByteString
toHeader :: PolicyId -> ByteString
$ctoQueryParam :: PolicyId -> Text
toQueryParam :: PolicyId -> Text
$ctoEncodedQueryParam :: PolicyId -> Builder
toEncodedQueryParam :: PolicyId -> Builder
ToHttpApiData, Maybe PolicyId
Value -> Parser [PolicyId]
Value -> Parser PolicyId
(Value -> Parser PolicyId)
-> (Value -> Parser [PolicyId])
-> Maybe PolicyId
-> FromJSON PolicyId
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser PolicyId
parseJSON :: Value -> Parser PolicyId
$cparseJSONList :: Value -> Parser [PolicyId]
parseJSONList :: Value -> Parser [PolicyId]
$comittedField :: Maybe PolicyId
omittedField :: Maybe PolicyId
FromJSON, [PolicyId] -> Value
[PolicyId] -> Encoding
PolicyId -> Bool
PolicyId -> Value
PolicyId -> Encoding
(PolicyId -> Value)
-> (PolicyId -> Encoding)
-> ([PolicyId] -> Value)
-> ([PolicyId] -> Encoding)
-> (PolicyId -> Bool)
-> ToJSON PolicyId
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: PolicyId -> Value
toJSON :: PolicyId -> Value
$ctoEncoding :: PolicyId -> Encoding
toEncoding :: PolicyId -> Encoding
$ctoJSONList :: [PolicyId] -> Value
toJSONList :: [PolicyId] -> Value
$ctoEncodingList :: [PolicyId] -> Encoding
toEncodingList :: [PolicyId] -> Encoding
$comitField :: PolicyId -> Bool
omitField :: PolicyId -> Bool
ToJSON)

mkPolicyId :: Text -> PolicyId
mkPolicyId :: Text -> PolicyId
mkPolicyId = Text -> PolicyId
PolicyId

unPolicyId :: PolicyId -> Text
unPolicyId :: PolicyId -> Text
unPolicyId (PolicyId Text
a) = Text
a

instance IsString PolicyId where
  fromString :: String -> PolicyId
fromString = Text -> PolicyId
mkPolicyId (Text -> PolicyId) -> (String -> Text) -> String -> PolicyId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
Data.Text.pack

instance ToCapture (Capture "policy_id" PolicyId) where
  toCapture :: Proxy (Capture "policy_id" PolicyId) -> DocCapture
toCapture Proxy (Capture "policy_id" PolicyId)
_ = String -> String -> DocCapture
DocCapture String
"policy_id" String
"Specific policy_id"

instance ToSample PolicyId where
    toSamples :: Proxy PolicyId -> [(Text, PolicyId)]
toSamples = [(Text, PolicyId)] -> Proxy PolicyId -> [(Text, PolicyId)]
forall a. a -> Proxy PolicyId -> a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([(Text, PolicyId)] -> Proxy PolicyId -> [(Text, PolicyId)])
-> [(Text, PolicyId)] -> Proxy PolicyId -> [(Text, PolicyId)]
forall a b. (a -> b) -> a -> b
$ [PolicyId] -> [(Text, PolicyId)]
forall a. [a] -> [(Text, a)]
samples [
        PolicyId
"476039a0949cf0b22f6a800f56780184c44533887ca6e821007840c3"
      ]