-- |  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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssetId -> AssetId -> Bool
$c/= :: AssetId -> AssetId -> Bool
== :: AssetId -> AssetId -> Bool
$c== :: AssetId -> AssetId -> Bool
Eq, Eq 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
min :: AssetId -> AssetId -> AssetId
$cmin :: AssetId -> AssetId -> AssetId
max :: AssetId -> AssetId -> AssetId
$cmax :: AssetId -> AssetId -> AssetId
>= :: AssetId -> AssetId -> Bool
$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
compare :: AssetId -> AssetId -> Ordering
$ccompare :: AssetId -> AssetId -> Ordering
Ord, Int -> AssetId -> ShowS
[AssetId] -> ShowS
AssetId -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssetId] -> ShowS
$cshowList :: [AssetId] -> ShowS
show :: AssetId -> String
$cshow :: AssetId -> String
showsPrec :: Int -> AssetId -> ShowS
$cshowsPrec :: Int -> AssetId -> ShowS
Show, 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
$cto :: forall x. Rep AssetId x -> AssetId
$cfrom :: forall x. AssetId -> Rep AssetId x
Generic)
  deriving newtype (ByteString -> Either Text AssetId
Text -> Either Text AssetId
forall a.
(Text -> Either Text a)
-> (ByteString -> Either Text a)
-> (Text -> Either Text a)
-> FromHttpApiData a
parseQueryParam :: Text -> Either Text AssetId
$cparseQueryParam :: Text -> Either Text AssetId
parseHeader :: ByteString -> Either Text AssetId
$cparseHeader :: ByteString -> Either Text AssetId
parseUrlPiece :: Text -> Either Text AssetId
$cparseUrlPiece :: Text -> Either Text AssetId
FromHttpApiData, AssetId -> Builder
AssetId -> ByteString
AssetId -> Text
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> (a -> Builder)
-> ToHttpApiData a
toEncodedQueryParam :: AssetId -> Builder
$ctoEncodedQueryParam :: AssetId -> Builder
toQueryParam :: AssetId -> Text
$ctoQueryParam :: AssetId -> Text
toHeader :: AssetId -> ByteString
$ctoHeader :: AssetId -> ByteString
toEncodedUrlPiece :: AssetId -> Builder
$ctoEncodedUrlPiece :: AssetId -> Builder
toUrlPiece :: AssetId -> Text
$ctoUrlPiece :: AssetId -> Text
ToHttpApiData, Maybe AssetId
Value -> Parser [AssetId]
Value -> Parser AssetId
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
omittedField :: Maybe AssetId
$comittedField :: Maybe AssetId
parseJSONList :: Value -> Parser [AssetId]
$cparseJSONList :: Value -> Parser [AssetId]
parseJSON :: Value -> Parser AssetId
$cparseJSON :: Value -> Parser AssetId
FromJSON, [AssetId] -> Encoding
[AssetId] -> Value
AssetId -> Bool
AssetId -> Encoding
AssetId -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
omitField :: AssetId -> Bool
$comitField :: AssetId -> Bool
toEncodingList :: [AssetId] -> Encoding
$ctoEncodingList :: [AssetId] -> Encoding
toJSONList :: [AssetId] -> Value
$ctoJSONList :: [AssetId] -> Value
toEncoding :: AssetId -> Encoding
$ctoEncoding :: AssetId -> Encoding
toJSON :: AssetId -> Value
$ctoJSON :: AssetId -> Value
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 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 = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [(Text, a)]
samples [
        AssetId
"b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e"
      , AssetId
"6804edf9712d2b619edb6ac86861fe93a730693183a262b165fcc1ba1bc99cad"
      ]