-- | Address newtype

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

mkAddress :: Text -> Address
mkAddress :: Text -> Address
mkAddress = Text -> Address
Address

unAddress :: Address -> Text
unAddress :: Address -> Text
unAddress (Address Text
a) = Text
a

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

instance ToCapture (Capture "address" Address) where
  toCapture :: Proxy (Capture "address" Address) -> DocCapture
toCapture Proxy (Capture "address" Address)
_ = String -> String -> DocCapture
DocCapture String
"address" String
"Bech32 encoded address"

instance ToCapture (Capture "stake_address" Address) where
  toCapture :: Proxy (Capture "stake_address" Address) -> DocCapture
toCapture Proxy (Capture "stake_address" Address)
_ = String -> String -> DocCapture
DocCapture String
"stake_address" String
"Bech32 stake address"

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