{-# OPTIONS --safe #-}

open import Data.Nat.Properties using (+-0-monoid)

open import Ledger.Prelude
open import Ledger.Conway.Types.GovStructure

module Ledger.Conway.GovernanceActions.Properties (gs : _) (open GovStructure gs) where

open import Ledger.Conway.GovernanceActions gs hiding (yes; no)
open import Ledger.Conway.Enact gs

open EnactState

instance
  _ = +-0-monoid

open Computational ⦃...⦄
instance
  Computational-ENACT : Computational _⊢_⇀⦇_,ENACT⦈_ String
  Computational-ENACT .computeProof Γᵉ s =
    let open EnactEnv Γᵉ renaming (treasury to t; epoch to e) in
    λ where
    $\begin{pmatrix} \,\href{Ledger.Conway.GovernanceActions.html#758}{\htmlId{603}{\htmlClass{InductiveConstructor}{\text{NoConfidence}}}}\, \\ \,\htmlId{618}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$                 success (_ , Enact-NoConf)
    $\begin{pmatrix} \,\href{Ledger.Conway.GovernanceActions.html#793}{\htmlId{674}{\htmlClass{InductiveConstructor}{\text{UpdateCommittee}}}}\, \\ (\,\href{Ledger.Conway.GovernanceActions.Properties.html#693}{\htmlId{693}{\htmlClass{Bound}{\text{new}}}}\, , \,\href{Ledger.Conway.GovernanceActions.Properties.html#699}{\htmlId{699}{\htmlClass{Bound}{\text{rem}}}}\, , \,\href{Ledger.Conway.GovernanceActions.Properties.html#705}{\htmlId{705}{\htmlClass{Bound}{\text{q}}}}\,) \end{pmatrix}$ 
      case ¿ ∀[ term  range new ]
               term  ccMaxTermLengthOf s +ᵉ' e ¿ of λ where
      (yes p)  success (-, Enact-UpdComm
        (subst  x  ∀[ term  range new ] term  x) (sym +ᵉ≡+ᵉ') p))
      (no ¬p)  failure "ENACT failed at ∀[ term ∈ range new ] term ≤ (ccMaxTermLengthOf s +ᵉ e)"
    $\begin{pmatrix} \,\href{Ledger.Conway.GovernanceActions.html#828}{\htmlId{1027}{\htmlClass{InductiveConstructor}{\text{NewConstitution}}}}\, \\ \,\htmlId{1045}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$  success (-, Enact-NewConst)
    $\begin{pmatrix} \,\href{Ledger.Conway.GovernanceActions.html#863}{\htmlId{1087}{\htmlClass{InductiveConstructor}{\text{TriggerHF}}}}\,       \\ \,\htmlId{1105}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$  success (-, Enact-HF)
    $\begin{pmatrix} \,\href{Ledger.Conway.GovernanceActions.html#898}{\htmlId{1141}{\htmlClass{InductiveConstructor}{\text{ChangePParams}}}}\,   \\ \,\htmlId{1159}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$  success (-, Enact-PParams)
    $\begin{pmatrix} \,\href{Ledger.Conway.GovernanceActions.html#968}{\htmlId{1200}{\htmlClass{InductiveConstructor}{\text{Info}}}}\,            \\ \,\htmlId{1218}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$  success (-, Enact-Info) 
    $\begin{pmatrix} \,\href{Ledger.Conway.GovernanceActions.html#933}{\htmlId{1257}{\htmlClass{InductiveConstructor}{\text{TreasuryWdrl}}}}\, \\ \,\href{Ledger.Conway.GovernanceActions.Properties.html#1272}{\htmlId{1272}{\htmlClass{Bound}{\text{wdrl}}}}\, \end{pmatrix}$ 
      case ¿ ∑[ x  s .withdrawals ∪⁺ wdrl ] x  t ¿ of λ where
        (yes p)              success (-, Enact-Wdrl p)
        (no _)               failure "ENACT failed at ∑[ x ← (s .withdrawals ∪⁺ wdrl) ᶠᵐ ] x ≤ t"
  Computational-ENACT .completeness Γᵉ s action _ p
    with action | p
  ... | $\begin{pmatrix} \,\htmlId{1584}{\htmlClass{DottedPattern Symbol}{\text{.}}}\,\,\href{Ledger.Conway.GovernanceActions.html#758}{\htmlId{1585}{\htmlClass{DottedPattern InductiveConstructor}{\text{NoConfidence}}}}\,    \\ \,\htmlId{1603}{\htmlClass{Symbol}{\text{\_}}}\,               \end{pmatrix}$ | Enact-NoConf   = refl
  ... | $\begin{pmatrix} \,\htmlId{1657}{\htmlClass{DottedPattern Symbol}{\text{.}}}\,\,\href{Ledger.Conway.GovernanceActions.html#793}{\htmlId{1658}{\htmlClass{DottedPattern InductiveConstructor}{\text{UpdateCommittee}}}}\, \\ (\,\href{Ledger.Conway.GovernanceActions.Properties.html#1677}{\htmlId{1677}{\htmlClass{Bound}{\text{new}}}}\, , \,\href{Ledger.Conway.GovernanceActions.Properties.html#1683}{\htmlId{1683}{\htmlClass{Bound}{\text{rem}}}}\, , \,\href{Ledger.Conway.GovernanceActions.Properties.html#1689}{\htmlId{1689}{\htmlClass{Bound}{\text{q}}}}\,) \end{pmatrix}$ | Enact-UpdComm p
    rewrite dec-yes
      (¿ ∀[ term  range new ] term
            ccMaxTermLengthOf s +ᵉ' EnactEnv.epoch Γᵉ ¿)
      (subst  x  ∀[ term  range new ] term  x) +ᵉ≡+ᵉ' p) .proj₂
      = refl
  ... | $\begin{pmatrix} \,\htmlId{1920}{\htmlClass{DottedPattern Symbol}{\text{.}}}\,\,\href{Ledger.Conway.GovernanceActions.html#828}{\htmlId{1921}{\htmlClass{DottedPattern InductiveConstructor}{\text{NewConstitution}}}}\, \\ \,\htmlId{1939}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$ | Enact-NewConst = refl
  ... | $\begin{pmatrix} \,\htmlId{1979}{\htmlClass{DottedPattern Symbol}{\text{.}}}\,\,\href{Ledger.Conway.GovernanceActions.html#863}{\htmlId{1980}{\htmlClass{DottedPattern InductiveConstructor}{\text{TriggerHF}}}}\,       \\ \,\htmlId{1998}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$ | Enact-HF       = refl
  ... | $\begin{pmatrix} \,\htmlId{2038}{\htmlClass{DottedPattern Symbol}{\text{.}}}\,\,\href{Ledger.Conway.GovernanceActions.html#898}{\htmlId{2039}{\htmlClass{DottedPattern InductiveConstructor}{\text{ChangePParams}}}}\,   \\ \,\htmlId{2057}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$ | Enact-PParams  = refl
  ... | $\begin{pmatrix} \,\htmlId{2097}{\htmlClass{DottedPattern Symbol}{\text{.}}}\,\,\href{Ledger.Conway.GovernanceActions.html#968}{\htmlId{2098}{\htmlClass{DottedPattern InductiveConstructor}{\text{Info}}}}\,            \\ \,\htmlId{2116}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$ | Enact-Info     = refl
  ... | $\begin{pmatrix} \,\htmlId{2156}{\htmlClass{DottedPattern Symbol}{\text{.}}}\,\,\href{Ledger.Conway.GovernanceActions.html#933}{\htmlId{2157}{\htmlClass{DottedPattern InductiveConstructor}{\text{TreasuryWdrl}}}}\, \\ \,\href{Ledger.Conway.GovernanceActions.Properties.html#2172}{\htmlId{2172}{\htmlClass{Bound}{\text{wdrl}}}}\, \end{pmatrix}$ | Enact-Wdrl p
    rewrite dec-yes (¿ ∑[ x  s .withdrawals ∪⁺ wdrl ] x  EnactEnv.treasury Γᵉ ¿) p .proj₂
    = refl