-- |
-- Module      :  Network.Ipfs.Api.Cid
-- Copyright   :  Aleksandr Krupenkin 2016-2021
-- License     :  Apache-2.0
--
-- Maintainer  :  mail@akru.me
-- Stability   :  experimental
-- Portability :  unknown
--
-- Api calls with `cid` prefix.
--

module Network.Ipfs.Api.Cid where

import           Control.Monad.IO.Class         (MonadIO)
import           Data.Text                      (Text)

import           Network.Ipfs.Api.Internal      (_cidBase32, _cidBases,
                                                 _cidCodecs, _cidFormat,
                                                 _cidHashes)
import           Network.Ipfs.Api.Internal.Call (call)
import           Network.Ipfs.Api.Types         (CidBasesObj, CidCodecsObj,
                                                 CidHashesObj, CidObj)
import           Network.Ipfs.Client            (IpfsT)

-- | List available multibase encodings.
bases :: MonadIO m => IpfsT m [CidBasesObj]
bases :: IpfsT m [CidBasesObj]
bases = ClientM [CidBasesObj] -> IpfsT m [CidBasesObj]
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call ClientM [CidBasesObj]
_cidBases

-- | List available CID codecs.
codecs :: MonadIO m => IpfsT m [CidCodecsObj]
codecs :: IpfsT m [CidCodecsObj]
codecs = ClientM [CidCodecsObj] -> IpfsT m [CidCodecsObj]
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call ClientM [CidCodecsObj]
_cidCodecs

-- | List available multihashes.
hashes :: MonadIO m => IpfsT m [CidHashesObj]
hashes :: IpfsT m [CidHashesObj]
hashes = ClientM [CidHashesObj] -> IpfsT m [CidHashesObj]
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call ClientM [CidHashesObj]
_cidHashes

-- | Convert CIDs to Base32 CID version 1.
base32 :: MonadIO m => Text -> IpfsT m CidObj
base32 :: Text -> IpfsT m CidObj
base32 = ClientM CidObj -> IpfsT m CidObj
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call (ClientM CidObj -> IpfsT m CidObj)
-> (Text -> ClientM CidObj) -> Text -> IpfsT m CidObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ClientM CidObj
_cidBase32

-- | Format and convert a CID in various useful ways.
format :: MonadIO m => Text -> IpfsT m CidObj
format :: Text -> IpfsT m CidObj
format = ClientM CidObj -> IpfsT m CidObj
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call (ClientM CidObj -> IpfsT m CidObj)
-> (Text -> ClientM CidObj) -> Text -> IpfsT m CidObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ClientM CidObj
_cidFormat