-- |  AssetIds

module Blockfrost.Types.Shared.AssetId
  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)

-- | Concatenation of asset policy ID
-- and hex-encoded asset name
newtype AssetId = AssetId Text
  deriving stock (AssetId -> AssetId -> Bool
(AssetId -> AssetId -> Bool)
-> (AssetId -> AssetId -> Bool) -> Eq AssetId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AssetId -> AssetId -> Bool
== :: AssetId -> AssetId -> Bool
$c/= :: AssetId -> AssetId -> Bool
/= :: AssetId -> AssetId -> Bool
Eq, Eq AssetId
Eq AssetId =>
(AssetId -> AssetId -> Ordering)
-> (AssetId -> AssetId -> Bool)
-> (AssetId -> AssetId -> Bool)
-> (AssetId -> AssetId -> Bool)
-> (AssetId -> AssetId -> Bool)
-> (AssetId -> AssetId -> AssetId)
-> (AssetId -> AssetId -> AssetId)
-> Ord AssetId
AssetId -> AssetId -> Bool
AssetId -> AssetId -> Ordering
AssetId -> AssetId -> AssetId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: AssetId -> AssetId -> Ordering
compare :: AssetId -> AssetId -> Ordering
$c< :: AssetId -> AssetId -> Bool
< :: AssetId -> AssetId -> Bool
$c<= :: AssetId -> AssetId -> Bool
<= :: AssetId -> AssetId -> Bool
$c> :: AssetId -> AssetId -> Bool
> :: AssetId -> AssetId -> Bool
$c>= :: AssetId -> AssetId -> Bool
>= :: AssetId -> AssetId -> Bool
$cmax :: AssetId -> AssetId -> AssetId
max :: AssetId -> AssetId -> AssetId
$cmin :: AssetId -> AssetId -> AssetId
min :: AssetId -> AssetId -> AssetId
Ord, Int -> AssetId -> ShowS
[AssetId] -> ShowS
AssetId -> String
(Int -> AssetId -> ShowS)
-> (AssetId -> String) -> ([AssetId] -> ShowS) -> Show AssetId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AssetId -> ShowS
showsPrec :: Int -> AssetId -> ShowS
$cshow :: AssetId -> String
show :: AssetId -> String
$cshowList :: [AssetId] -> ShowS
showList :: [AssetId] -> ShowS
Show, (forall x. AssetId -> Rep AssetId x)
-> (forall x. Rep AssetId x -> AssetId) -> Generic AssetId
forall x. Rep AssetId x -> AssetId
forall x. AssetId -> Rep AssetId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. AssetId -> Rep AssetId x
from :: forall x. AssetId -> Rep AssetId x
$cto :: forall x. Rep AssetId x -> AssetId
to :: forall x. Rep AssetId x -> AssetId
Generic)
  deriving newtype (Text -> Either Text AssetId
ByteString -> Either Text AssetId
(Text -> Either Text AssetId)
-> (ByteString -> Either Text AssetId)
-> (Text -> Either Text AssetId)
-> FromHttpApiData AssetId
forall a.
(Text -> Either Text a)
-> (ByteString -> Either Text a)
-> (Text -> Either Text a)
-> FromHttpApiData a
$cparseUrlPiece :: Text -> Either Text AssetId
parseUrlPiece :: Text -> Either Text AssetId
$cparseHeader :: ByteString -> Either Text AssetId
parseHeader :: ByteString -> Either Text AssetId
$cparseQueryParam :: Text -> Either Text AssetId
parseQueryParam :: Text -> Either Text AssetId
FromHttpApiData, AssetId -> Text
AssetId -> ByteString
AssetId -> Builder
(AssetId -> Text)
-> (AssetId -> Builder)
-> (AssetId -> ByteString)
-> (AssetId -> Text)
-> (AssetId -> Builder)
-> ToHttpApiData AssetId
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> (a -> Builder)
-> ToHttpApiData a
$ctoUrlPiece :: AssetId -> Text
toUrlPiece :: AssetId -> Text
$ctoEncodedUrlPiece :: AssetId -> Builder
toEncodedUrlPiece :: AssetId -> Builder
$ctoHeader :: AssetId -> ByteString
toHeader :: AssetId -> ByteString
$ctoQueryParam :: AssetId -> Text
toQueryParam :: AssetId -> Text
$ctoEncodedQueryParam :: AssetId -> Builder
toEncodedQueryParam :: AssetId -> Builder
ToHttpApiData, Maybe AssetId
Value -> Parser [AssetId]
Value -> Parser AssetId
(Value -> Parser AssetId)
-> (Value -> Parser [AssetId]) -> Maybe AssetId -> FromJSON AssetId
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser AssetId
parseJSON :: Value -> Parser AssetId
$cparseJSONList :: Value -> Parser [AssetId]
parseJSONList :: Value -> Parser [AssetId]
$comittedField :: Maybe AssetId
omittedField :: Maybe AssetId
FromJSON, [AssetId] -> Value
[AssetId] -> Encoding
AssetId -> Bool
AssetId -> Value
AssetId -> Encoding
(AssetId -> Value)
-> (AssetId -> Encoding)
-> ([AssetId] -> Value)
-> ([AssetId] -> Encoding)
-> (AssetId -> Bool)
-> ToJSON AssetId
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: AssetId -> Value
toJSON :: AssetId -> Value
$ctoEncoding :: AssetId -> Encoding
toEncoding :: AssetId -> Encoding
$ctoJSONList :: [AssetId] -> Value
toJSONList :: [AssetId] -> Value
$ctoEncodingList :: [AssetId] -> Encoding
toEncodingList :: [AssetId] -> Encoding
$comitField :: AssetId -> Bool
omitField :: AssetId -> Bool
ToJSON)

mkAssetId :: Text -> AssetId
mkAssetId :: Text -> AssetId
mkAssetId = Text -> AssetId
AssetId

unAssetId :: AssetId -> Text
unAssetId :: AssetId -> Text
unAssetId (AssetId Text
a) = Text
a

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

instance ToCapture (Capture "asset" AssetId) where
  toCapture :: Proxy (Capture "asset" AssetId) -> DocCapture
toCapture Proxy (Capture "asset" AssetId)
_ = String -> String -> DocCapture
DocCapture String
"asset" String
"Concatenation of the policy_id and hex-encoded asset_name"

instance ToSample AssetId where
    toSamples :: Proxy AssetId -> [(Text, AssetId)]
toSamples = [(Text, AssetId)] -> Proxy AssetId -> [(Text, AssetId)]
forall a. a -> Proxy AssetId -> a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([(Text, AssetId)] -> Proxy AssetId -> [(Text, AssetId)])
-> [(Text, AssetId)] -> Proxy AssetId -> [(Text, AssetId)]
forall a b. (a -> b) -> a -> b
$ [AssetId] -> [(Text, AssetId)]
forall a. [a] -> [(Text, a)]
samples [
        AssetId
"b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e"
      , AssetId
"6804edf9712d2b619edb6ac86861fe93a730693183a262b165fcc1ba1bc99cad"
      ]