-- | Pool identifier

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

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

mkPoolId :: Text -> PoolId
mkPoolId :: Text -> PoolId
mkPoolId = Text -> PoolId
PoolId

unPoolId :: PoolId -> Text
unPoolId :: PoolId -> Text
unPoolId (PoolId Text
a) = Text
a

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

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

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