{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}

module Cardano.Api.Eon.BabbageEraOnwards
  ( BabbageEraOnwards (..)
  , babbageEraOnwardsConstraints
  , babbageEraOnwardsToShelleyBasedEra
  , BabbageEraOnwardsConstraints
  , IsBabbageBasedEra (..)
  )
where

import           Cardano.Api.Eon.AlonzoEraOnwards
import           Cardano.Api.Eon.Convert
import           Cardano.Api.Eon.MaryEraOnwards
import           Cardano.Api.Eon.ShelleyBasedEra
import           Cardano.Api.Eras.Core
import           Cardano.Api.Modes
import           Cardano.Api.Query.Types

import           Cardano.Binary
import qualified Cardano.Crypto.Hash.Blake2b as Blake2b
import qualified Cardano.Crypto.Hash.Class as C
import qualified Cardano.Crypto.VRF as C
import qualified Cardano.Ledger.Alonzo.Scripts as L
import qualified Cardano.Ledger.Alonzo.UTxO as L
import qualified Cardano.Ledger.Api as L
import qualified Cardano.Ledger.Babbage.TxOut as L
import qualified Cardano.Ledger.BaseTypes as L
import qualified Cardano.Ledger.Core as L
import qualified Cardano.Ledger.Mary.Value as L
import qualified Cardano.Ledger.SafeHash as L
import qualified Cardano.Ledger.UTxO as L
import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus
import qualified Ouroboros.Consensus.Protocol.Praos.Common as Consensus
import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus

import           Data.Aeson
import           Data.Typeable (Typeable)

data BabbageEraOnwards era where
  BabbageEraOnwardsBabbage :: BabbageEraOnwards BabbageEra
  BabbageEraOnwardsConway :: BabbageEraOnwards ConwayEra

deriving instance Show (BabbageEraOnwards era)

deriving instance Eq (BabbageEraOnwards era)

instance Eon BabbageEraOnwards where
  inEonForEra :: forall a era.
a -> (BabbageEraOnwards era -> a) -> CardanoEra era -> a
inEonForEra a
no BabbageEraOnwards era -> a
yes = \case
    CardanoEra era
ByronEra -> a
no
    CardanoEra era
ShelleyEra -> a
no
    CardanoEra era
AllegraEra -> a
no
    CardanoEra era
MaryEra -> a
no
    CardanoEra era
AlonzoEra -> a
no
    CardanoEra era
BabbageEra -> BabbageEraOnwards era -> a
yes BabbageEraOnwards era
BabbageEraOnwards BabbageEra
BabbageEraOnwardsBabbage
    CardanoEra era
ConwayEra -> BabbageEraOnwards era -> a
yes BabbageEraOnwards era
BabbageEraOnwards ConwayEra
BabbageEraOnwardsConway

instance ToCardanoEra BabbageEraOnwards where
  toCardanoEra :: forall era. BabbageEraOnwards era -> CardanoEra era
toCardanoEra = \case
    BabbageEraOnwards era
BabbageEraOnwardsBabbage -> CardanoEra era
CardanoEra BabbageEra
BabbageEra
    BabbageEraOnwards era
BabbageEraOnwardsConway -> CardanoEra era
CardanoEra ConwayEra
ConwayEra

instance Convert BabbageEraOnwards CardanoEra where
  convert :: forall era. BabbageEraOnwards era -> CardanoEra era
convert = BabbageEraOnwards era -> CardanoEra era
forall era. BabbageEraOnwards era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra

instance Convert BabbageEraOnwards ShelleyBasedEra where
  convert :: forall era. BabbageEraOnwards era -> ShelleyBasedEra era
convert = \case
    BabbageEraOnwards era
BabbageEraOnwardsBabbage -> ShelleyBasedEra era
ShelleyBasedEra BabbageEra
ShelleyBasedEraBabbage
    BabbageEraOnwards era
BabbageEraOnwardsConway -> ShelleyBasedEra era
ShelleyBasedEra ConwayEra
ShelleyBasedEraConway

instance Convert BabbageEraOnwards MaryEraOnwards where
  convert :: forall era. BabbageEraOnwards era -> MaryEraOnwards era
convert = \case
    BabbageEraOnwards era
BabbageEraOnwardsBabbage -> MaryEraOnwards era
MaryEraOnwards BabbageEra
MaryEraOnwardsBabbage
    BabbageEraOnwards era
BabbageEraOnwardsConway -> MaryEraOnwards era
MaryEraOnwards ConwayEra
MaryEraOnwardsConway

type BabbageEraOnwardsConstraints era =
  ( C.HashAlgorithm (L.HASH (L.EraCrypto (ShelleyLedgerEra era)))
  , C.Signable (L.VRF (L.EraCrypto (ShelleyLedgerEra era))) L.Seed
  , Consensus.PraosProtocolSupportsNode (ConsensusProtocol era)
  , Consensus.ShelleyBlock (ConsensusProtocol era) (ShelleyLedgerEra era) ~ ConsensusBlockForEra era
  , Consensus.ShelleyCompatible (ConsensusProtocol era) (ShelleyLedgerEra era)
  , L.ADDRHASH (Consensus.PraosProtocolSupportsNodeCrypto (ConsensusProtocol era)) ~ Blake2b.Blake2b_224
  , L.AlonzoEraTxOut (ShelleyLedgerEra era)
  , L.BabbageEraPParams (ShelleyLedgerEra era)
  , L.BabbageEraTxBody (ShelleyLedgerEra era)
  , L.BabbageEraTxOut (ShelleyLedgerEra era)
  , L.Crypto (L.EraCrypto (ShelleyLedgerEra era))
  , L.Era (ShelleyLedgerEra era)
  , L.EraCrypto (ShelleyLedgerEra era) ~ L.StandardCrypto
  , L.EraPParams (ShelleyLedgerEra era)
  , L.EraTx (ShelleyLedgerEra era)
  , L.EraTxBody (ShelleyLedgerEra era)
  , L.EraTxOut (ShelleyLedgerEra era)
  , L.EraUTxO (ShelleyLedgerEra era)
  , L.HashAnnotated (L.TxBody (ShelleyLedgerEra era)) L.EraIndependentTxBody L.StandardCrypto
  , L.MaryEraTxBody (ShelleyLedgerEra era)
  , L.Script (ShelleyLedgerEra era) ~ L.AlonzoScript (ShelleyLedgerEra era)
  , L.ScriptsNeeded (ShelleyLedgerEra era) ~ L.AlonzoScriptsNeeded (ShelleyLedgerEra era)
  , L.ShelleyEraTxCert (ShelleyLedgerEra era)
  , L.TxOut (ShelleyLedgerEra era) ~ L.BabbageTxOut (ShelleyLedgerEra era)
  , L.Value (ShelleyLedgerEra era) ~ L.MaryValue L.StandardCrypto
  , FromCBOR (Consensus.ChainDepState (ConsensusProtocol era))
  , FromCBOR (DebugLedgerState era)
  , IsCardanoEra era
  , IsShelleyBasedEra era
  , ToJSON (DebugLedgerState era)
  , Typeable era
  )

babbageEraOnwardsConstraints
  :: ()
  => BabbageEraOnwards era
  -> (BabbageEraOnwardsConstraints era => a)
  -> a
babbageEraOnwardsConstraints :: forall era a.
BabbageEraOnwards era
-> (BabbageEraOnwardsConstraints era => a) -> a
babbageEraOnwardsConstraints = \case
  BabbageEraOnwards era
BabbageEraOnwardsBabbage -> a -> a
(BabbageEraOnwardsConstraints era => a) -> a
forall a. a -> a
id
  BabbageEraOnwards era
BabbageEraOnwardsConway -> a -> a
(BabbageEraOnwardsConstraints era => a) -> a
forall a. a -> a
id

{-# DEPRECATED babbageEraOnwardsToShelleyBasedEra "Use 'convert' instead." #-}
babbageEraOnwardsToShelleyBasedEra :: BabbageEraOnwards era -> ShelleyBasedEra era
babbageEraOnwardsToShelleyBasedEra :: forall era. BabbageEraOnwards era -> ShelleyBasedEra era
babbageEraOnwardsToShelleyBasedEra = BabbageEraOnwards era -> ShelleyBasedEra era
forall era. BabbageEraOnwards era -> ShelleyBasedEra era
forall a (f :: a -> *) (g :: a -> *) (era :: a).
Convert f g =>
f era -> g era
convert

class IsAlonzoBasedEra era => IsBabbageBasedEra era where
  babbageBasedEra :: BabbageEraOnwards era

instance IsBabbageBasedEra BabbageEra where
  babbageBasedEra :: BabbageEraOnwards BabbageEra
babbageBasedEra = BabbageEraOnwards BabbageEra
BabbageEraOnwardsBabbage

instance IsBabbageBasedEra ConwayEra where
  babbageBasedEra :: BabbageEraOnwards ConwayEra
babbageBasedEra = BabbageEraOnwards ConwayEra
BabbageEraOnwardsConway