-- | Slot wrapper

module Blockfrost.Types.Shared.Slot
  where

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

newtype Slot = Slot Integer
  deriving stock (Slot -> Slot -> Bool
(Slot -> Slot -> Bool) -> (Slot -> Slot -> Bool) -> Eq Slot
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Slot -> Slot -> Bool
$c/= :: Slot -> Slot -> Bool
== :: Slot -> Slot -> Bool
$c== :: Slot -> Slot -> Bool
Eq, Int -> Slot -> ShowS
[Slot] -> ShowS
Slot -> String
(Int -> Slot -> ShowS)
-> (Slot -> String) -> ([Slot] -> ShowS) -> Show Slot
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Slot] -> ShowS
$cshowList :: [Slot] -> ShowS
show :: Slot -> String
$cshow :: Slot -> String
showsPrec :: Int -> Slot -> ShowS
$cshowsPrec :: Int -> Slot -> ShowS
Show, (forall x. Slot -> Rep Slot x)
-> (forall x. Rep Slot x -> Slot) -> Generic Slot
forall x. Rep Slot x -> Slot
forall x. Slot -> Rep Slot x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Slot x -> Slot
$cfrom :: forall x. Slot -> Rep Slot x
Generic)
  deriving newtype (Integer -> Slot
Slot -> Slot
Slot -> Slot -> Slot
(Slot -> Slot -> Slot)
-> (Slot -> Slot -> Slot)
-> (Slot -> Slot -> Slot)
-> (Slot -> Slot)
-> (Slot -> Slot)
-> (Slot -> Slot)
-> (Integer -> Slot)
-> Num Slot
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> Slot
$cfromInteger :: Integer -> Slot
signum :: Slot -> Slot
$csignum :: Slot -> Slot
abs :: Slot -> Slot
$cabs :: Slot -> Slot
negate :: Slot -> Slot
$cnegate :: Slot -> Slot
* :: Slot -> Slot -> Slot
$c* :: Slot -> Slot -> Slot
- :: Slot -> Slot -> Slot
$c- :: Slot -> Slot -> Slot
+ :: Slot -> Slot -> Slot
$c+ :: Slot -> Slot -> Slot
Num, ByteString -> Either Text Slot
Text -> Either Text Slot
(Text -> Either Text Slot)
-> (ByteString -> Either Text Slot)
-> (Text -> Either Text Slot)
-> FromHttpApiData Slot
forall a.
(Text -> Either Text a)
-> (ByteString -> Either Text a)
-> (Text -> Either Text a)
-> FromHttpApiData a
parseQueryParam :: Text -> Either Text Slot
$cparseQueryParam :: Text -> Either Text Slot
parseHeader :: ByteString -> Either Text Slot
$cparseHeader :: ByteString -> Either Text Slot
parseUrlPiece :: Text -> Either Text Slot
$cparseUrlPiece :: Text -> Either Text Slot
FromHttpApiData, Slot -> ByteString
Slot -> Builder
Slot -> Text
(Slot -> Text)
-> (Slot -> Builder)
-> (Slot -> ByteString)
-> (Slot -> Text)
-> ToHttpApiData Slot
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> ToHttpApiData a
toQueryParam :: Slot -> Text
$ctoQueryParam :: Slot -> Text
toHeader :: Slot -> ByteString
$ctoHeader :: Slot -> ByteString
toEncodedUrlPiece :: Slot -> Builder
$ctoEncodedUrlPiece :: Slot -> Builder
toUrlPiece :: Slot -> Text
$ctoUrlPiece :: Slot -> Text
ToHttpApiData, Value -> Parser [Slot]
Value -> Parser Slot
(Value -> Parser Slot) -> (Value -> Parser [Slot]) -> FromJSON Slot
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [Slot]
$cparseJSONList :: Value -> Parser [Slot]
parseJSON :: Value -> Parser Slot
$cparseJSON :: Value -> Parser Slot
FromJSON, [Slot] -> Encoding
[Slot] -> Value
Slot -> Encoding
Slot -> Value
(Slot -> Value)
-> (Slot -> Encoding)
-> ([Slot] -> Value)
-> ([Slot] -> Encoding)
-> ToJSON Slot
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [Slot] -> Encoding
$ctoEncodingList :: [Slot] -> Encoding
toJSONList :: [Slot] -> Value
$ctoJSONList :: [Slot] -> Value
toEncoding :: Slot -> Encoding
$ctoEncoding :: Slot -> Encoding
toJSON :: Slot -> Value
$ctoJSON :: Slot -> Value
ToJSON)

unSlot :: Slot -> Integer
unSlot :: Slot -> Integer
unSlot (Slot Integer
i) = Integer
i

instance ToCapture (Capture "slot_number" Slot) where
  toCapture :: Proxy (Capture "slot_number" Slot) -> DocCapture
toCapture Proxy (Capture "slot_number" Slot)
_ = String -> String -> DocCapture
DocCapture String
"slot_number" String
"Slot position for requested block."

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