-- | Metadata queries

module Blockfrost.Client.Cardano.Metadata
  ( getTxMetadataLabels
  , getTxMetadataLabels'
  , getTxMetadataByLabelJSON
  , getTxMetadataByLabelJSON'
  , getTxMetadataByLabelCBOR
  , getTxMetadataByLabelCBOR'
  ) where

import Blockfrost.API
import Blockfrost.Client.Types
import Blockfrost.Types
import Data.Text (Text)

metadataClient :: MonadBlockfrost m => Project -> MetadataAPI (AsClientT m)
metadataClient :: Project -> MetadataAPI (AsClientT m)
metadataClient = ((Paged -> SortOrder -> m [TxMeta])
 :<|> ((Text -> Paged -> SortOrder -> m [TxMetaJSON])
       :<|> (Text -> Paged -> SortOrder -> m [TxMetaCBOR])))
-> MetadataAPI (AsClientT m)
forall (routes :: * -> *) mode.
GenericServant routes mode =>
ToServant routes mode -> routes mode
fromServant (((Paged -> SortOrder -> m [TxMeta])
  :<|> ((Text -> Paged -> SortOrder -> m [TxMetaJSON])
        :<|> (Text -> Paged -> SortOrder -> m [TxMetaCBOR])))
 -> MetadataAPI (AsClientT m))
-> (Project
    -> (Paged -> SortOrder -> m [TxMeta])
       :<|> ((Text -> Paged -> SortOrder -> m [TxMetaJSON])
             :<|> (Text -> Paged -> SortOrder -> m [TxMetaCBOR])))
-> Project
-> MetadataAPI (AsClientT m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CardanoAPI (AsClientT m)
-> (Paged -> SortOrder -> m [TxMeta])
   :<|> ((Text -> Paged -> SortOrder -> m [TxMetaJSON])
         :<|> (Text -> Paged -> SortOrder -> m [TxMetaCBOR]))
forall route.
CardanoAPI route
-> route
   :- ("metadata"
       :> (Tag "Cardano \187 Metadata" :> ToServantApi MetadataAPI))
_metadata (CardanoAPI (AsClientT m)
 -> (Paged -> SortOrder -> m [TxMeta])
    :<|> ((Text -> Paged -> SortOrder -> m [TxMetaJSON])
          :<|> (Text -> Paged -> SortOrder -> m [TxMetaCBOR])))
-> (Project -> CardanoAPI (AsClientT m))
-> Project
-> (Paged -> SortOrder -> m [TxMeta])
   :<|> ((Text -> Paged -> SortOrder -> m [TxMetaJSON])
         :<|> (Text -> Paged -> SortOrder -> m [TxMetaCBOR]))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> CardanoAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> CardanoAPI (AsClientT m)
cardanoClient

getTxMetadataLabels_ :: MonadBlockfrost m => Project -> Paged -> SortOrder -> m [TxMeta]
getTxMetadataLabels_ :: Project -> Paged -> SortOrder -> m [TxMeta]
getTxMetadataLabels_ = MetadataAPI (AsClientT m) -> Paged -> SortOrder -> m [TxMeta]
forall route.
MetadataAPI route
-> route
   :- (Summary "Transaction metadata labels"
       :> (Description "List of all used transaction metadata labels."
           :> ("txs"
               :> ("labels"
                   :> (Pagination :> (Sorting :> Get '[JSON] [TxMeta]))))))
_txMetadataLabels (MetadataAPI (AsClientT m) -> Paged -> SortOrder -> m [TxMeta])
-> (Project -> MetadataAPI (AsClientT m))
-> Project
-> Paged
-> SortOrder
-> m [TxMeta]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> MetadataAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> MetadataAPI (AsClientT m)
metadataClient

-- | List of all used transaction metadata labels.
-- Allows custom paging and ordering using @Paged@ and @SortOrder@.
getTxMetadataLabels' :: MonadBlockfrost m => Paged -> SortOrder -> m [TxMeta]
getTxMetadataLabels' :: Paged -> SortOrder -> m [TxMeta]
getTxMetadataLabels' Paged
pg SortOrder
s = (Project -> m [TxMeta]) -> m [TxMeta]
forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (\Project
p -> Project -> Paged -> SortOrder -> m [TxMeta]
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> Paged -> SortOrder -> m [TxMeta]
getTxMetadataLabels_ Project
p Paged
pg SortOrder
s)

-- | List of all used transaction metadata labels.
getTxMetadataLabels :: MonadBlockfrost m => m [TxMeta]
getTxMetadataLabels :: m [TxMeta]
getTxMetadataLabels = Paged -> SortOrder -> m [TxMeta]
forall (m :: * -> *).
MonadBlockfrost m =>
Paged -> SortOrder -> m [TxMeta]
getTxMetadataLabels' Paged
forall a. Default a => a
def SortOrder
forall a. Default a => a
def

getTxMetadataByLabelJSON_ :: MonadBlockfrost m => Project -> Text -> Paged -> SortOrder -> m [TxMetaJSON]
getTxMetadataByLabelJSON_ :: Project -> Text -> Paged -> SortOrder -> m [TxMetaJSON]
getTxMetadataByLabelJSON_ = MetadataAPI (AsClientT m)
-> Text -> Paged -> SortOrder -> m [TxMetaJSON]
forall route.
MetadataAPI route
-> route
   :- (Summary "Transaction metadata content in JSON"
       :> (Description "Transaction metadata per label."
           :> ("txs"
               :> ("labels"
                   :> (Capture "label" Text
                       :> (Pagination :> (Sorting :> Get '[JSON] [TxMetaJSON])))))))
_txMetadataByLabelJSON (MetadataAPI (AsClientT m)
 -> Text -> Paged -> SortOrder -> m [TxMetaJSON])
-> (Project -> MetadataAPI (AsClientT m))
-> Project
-> Text
-> Paged
-> SortOrder
-> m [TxMetaJSON]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> MetadataAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> MetadataAPI (AsClientT m)
metadataClient

-- | Transaction metadata per label (JSON @Value@)
-- Allows custom paging and ordering using @Paged@ and @SortOrder@.
getTxMetadataByLabelJSON' :: MonadBlockfrost m => Text -> Paged -> SortOrder -> m [TxMetaJSON]
getTxMetadataByLabelJSON' :: Text -> Paged -> SortOrder -> m [TxMetaJSON]
getTxMetadataByLabelJSON' Text
t Paged
pg SortOrder
s = (Project -> m [TxMetaJSON]) -> m [TxMetaJSON]
forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (\Project
p -> Project -> Text -> Paged -> SortOrder -> m [TxMetaJSON]
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> Text -> Paged -> SortOrder -> m [TxMetaJSON]
getTxMetadataByLabelJSON_ Project
p Text
t Paged
pg SortOrder
s)

-- | Transaction metadata per label (JSON @Value@)
getTxMetadataByLabelJSON :: MonadBlockfrost m => Text -> m [TxMetaJSON]
getTxMetadataByLabelJSON :: Text -> m [TxMetaJSON]
getTxMetadataByLabelJSON Text
t = Text -> Paged -> SortOrder -> m [TxMetaJSON]
forall (m :: * -> *).
MonadBlockfrost m =>
Text -> Paged -> SortOrder -> m [TxMetaJSON]
getTxMetadataByLabelJSON' Text
t Paged
forall a. Default a => a
def SortOrder
forall a. Default a => a
def

getTxMetadataByLabelCBOR_ :: MonadBlockfrost m => Project -> Text -> Paged -> SortOrder -> m [TxMetaCBOR]
getTxMetadataByLabelCBOR_ :: Project -> Text -> Paged -> SortOrder -> m [TxMetaCBOR]
getTxMetadataByLabelCBOR_ = MetadataAPI (AsClientT m)
-> Text -> Paged -> SortOrder -> m [TxMetaCBOR]
forall route.
MetadataAPI route
-> route
   :- (Summary "Transaction metadata content in CBOR"
       :> (Description "Transaction metadata per label."
           :> ("txs"
               :> ("labels"
                   :> (Capture "label" Text
                       :> ("cbor"
                           :> (Pagination :> (Sorting :> Get '[JSON] [TxMetaCBOR]))))))))
_txMetadataByLabelCBOR (MetadataAPI (AsClientT m)
 -> Text -> Paged -> SortOrder -> m [TxMetaCBOR])
-> (Project -> MetadataAPI (AsClientT m))
-> Project
-> Text
-> Paged
-> SortOrder
-> m [TxMetaCBOR]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Project -> MetadataAPI (AsClientT m)
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> MetadataAPI (AsClientT m)
metadataClient

-- | Transaction metadata per label (CBOR @ByteString@)
-- Allows custom paging and ordering using @Paged@ and @SortOrder@.
getTxMetadataByLabelCBOR' :: MonadBlockfrost m => Text -> Paged -> SortOrder -> m [TxMetaCBOR]
getTxMetadataByLabelCBOR' :: Text -> Paged -> SortOrder -> m [TxMetaCBOR]
getTxMetadataByLabelCBOR' Text
t Paged
pg SortOrder
s = (Project -> m [TxMetaCBOR]) -> m [TxMetaCBOR]
forall (m :: * -> *) a.
MonadBlockfrost m =>
(Project -> m a) -> m a
go (\Project
p -> Project -> Text -> Paged -> SortOrder -> m [TxMetaCBOR]
forall (m :: * -> *).
MonadBlockfrost m =>
Project -> Text -> Paged -> SortOrder -> m [TxMetaCBOR]
getTxMetadataByLabelCBOR_ Project
p Text
t Paged
pg SortOrder
s)

-- | Transaction metadata per label (CBOR @ByteString@)
getTxMetadataByLabelCBOR :: MonadBlockfrost m => Text -> m [TxMetaCBOR]
getTxMetadataByLabelCBOR :: Text -> m [TxMetaCBOR]
getTxMetadataByLabelCBOR Text
t = Text -> Paged -> SortOrder -> m [TxMetaCBOR]
forall (m :: * -> *).
MonadBlockfrost m =>
Text -> Paged -> SortOrder -> m [TxMetaCBOR]
getTxMetadataByLabelCBOR' Text
t Paged
forall a. Default a => a
def SortOrder
forall a. Default a => a
def