{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}

module Cardano.Api.Governance.Metadata.Validation (GovActionMetadata (..), Authors, Body, HashAlgorithm, validateGovActionAnchorData) where

import           Data.Aeson (FromJSON, eitherDecodeStrict)
import           Data.ByteString (ByteString)
import           Data.Either.Combinators (mapRight)

data GovActionMetadata cip
  = GovActionMetadata
  { forall cip. GovActionMetadata cip -> HashAlgorithm cip
hashAlgorithm :: HashAlgorithm cip
  , forall cip. GovActionMetadata cip -> Authors cip
authors :: Authors cip
  , forall cip. GovActionMetadata cip -> Body cip
body :: Body cip
  }

data family Authors cip

data family Body cip

data family HashAlgorithm cip

validateGovActionAnchorData
  :: forall cip. FromJSON (GovActionMetadata cip) => cip -> ByteString -> Either String ()
validateGovActionAnchorData :: forall cip.
FromJSON (GovActionMetadata cip) =>
cip -> ByteString -> Either String ()
validateGovActionAnchorData cip
cip ByteString
bytes = (GovActionMetadata cip -> ())
-> Either String (GovActionMetadata cip) -> Either String ()
forall b c a. (b -> c) -> Either a b -> Either a c
mapRight (() -> GovActionMetadata cip -> ()
forall a b. a -> b -> a
const ()) (cip -> ByteString -> Either String (GovActionMetadata cip)
decodeGovAction cip
cip ByteString
bytes)
 where
  decodeGovAction :: cip -> ByteString -> Either String (GovActionMetadata cip)
  decodeGovAction :: cip -> ByteString -> Either String (GovActionMetadata cip)
decodeGovAction cip
_ = ByteString -> Either String (GovActionMetadata cip)
forall a. FromJSON a => ByteString -> Either String a
eitherDecodeStrict