-- | 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, Eq Slot
Eq Slot
-> (Slot -> Slot -> Ordering)
-> (Slot -> Slot -> Bool)
-> (Slot -> Slot -> Bool)
-> (Slot -> Slot -> Bool)
-> (Slot -> Slot -> Bool)
-> (Slot -> Slot -> Slot)
-> (Slot -> Slot -> Slot)
-> Ord Slot
Slot -> Slot -> Bool
Slot -> Slot -> Ordering
Slot -> Slot -> Slot
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 :: Slot -> Slot -> Slot
$cmin :: Slot -> Slot -> Slot
max :: Slot -> Slot -> Slot
$cmax :: Slot -> Slot -> Slot
>= :: Slot -> Slot -> Bool
$c>= :: Slot -> Slot -> Bool
> :: Slot -> Slot -> Bool
$c> :: Slot -> Slot -> Bool
<= :: Slot -> Slot -> Bool
$c<= :: Slot -> Slot -> Bool
< :: Slot -> Slot -> Bool
$c< :: Slot -> Slot -> Bool
compare :: Slot -> Slot -> Ordering
$ccompare :: Slot -> Slot -> Ordering
$cp1Ord :: Eq Slot
Ord, 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, Int -> Slot
Slot -> Int
Slot -> [Slot]
Slot -> Slot
Slot -> Slot -> [Slot]
Slot -> Slot -> Slot -> [Slot]
(Slot -> Slot)
-> (Slot -> Slot)
-> (Int -> Slot)
-> (Slot -> Int)
-> (Slot -> [Slot])
-> (Slot -> Slot -> [Slot])
-> (Slot -> Slot -> [Slot])
-> (Slot -> Slot -> Slot -> [Slot])
-> Enum Slot
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Slot -> Slot -> Slot -> [Slot]
$cenumFromThenTo :: Slot -> Slot -> Slot -> [Slot]
enumFromTo :: Slot -> Slot -> [Slot]
$cenumFromTo :: Slot -> Slot -> [Slot]
enumFromThen :: Slot -> Slot -> [Slot]
$cenumFromThen :: Slot -> Slot -> [Slot]
enumFrom :: Slot -> [Slot]
$cenumFrom :: Slot -> [Slot]
fromEnum :: Slot -> Int
$cfromEnum :: Slot -> Int
toEnum :: Int -> Slot
$ctoEnum :: Int -> Slot
pred :: Slot -> Slot
$cpred :: Slot -> Slot
succ :: Slot -> Slot
$csucc :: Slot -> Slot
Enum, Num Slot
Ord Slot
Num Slot -> Ord Slot -> (Slot -> Rational) -> Real Slot
Slot -> Rational
forall a. Num a -> Ord a -> (a -> Rational) -> Real a
toRational :: Slot -> Rational
$ctoRational :: Slot -> Rational
$cp2Real :: Ord Slot
$cp1Real :: Num Slot
Real, Enum Slot
Real Slot
Real Slot
-> Enum Slot
-> (Slot -> Slot -> Slot)
-> (Slot -> Slot -> Slot)
-> (Slot -> Slot -> Slot)
-> (Slot -> Slot -> Slot)
-> (Slot -> Slot -> (Slot, Slot))
-> (Slot -> Slot -> (Slot, Slot))
-> (Slot -> Integer)
-> Integral Slot
Slot -> Integer
Slot -> Slot -> (Slot, Slot)
Slot -> Slot -> Slot
forall a.
Real a
-> Enum a
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
toInteger :: Slot -> Integer
$ctoInteger :: Slot -> Integer
divMod :: Slot -> Slot -> (Slot, Slot)
$cdivMod :: Slot -> Slot -> (Slot, Slot)
quotRem :: Slot -> Slot -> (Slot, Slot)
$cquotRem :: Slot -> Slot -> (Slot, Slot)
mod :: Slot -> Slot -> Slot
$cmod :: Slot -> Slot -> Slot
div :: Slot -> Slot -> Slot
$cdiv :: Slot -> Slot -> Slot
rem :: Slot -> Slot -> Slot
$crem :: Slot -> Slot -> Slot
quot :: Slot -> Slot -> Slot
$cquot :: Slot -> Slot -> Slot
$cp2Integral :: Enum Slot
$cp1Integral :: Real Slot
Integral, 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]