{-# OPTIONS --safe #-}

open import Ledger.Conway.Gov.Base

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

open import Ledger.Prelude

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

open EnactState

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.Gov.Actions.html#710}{\htmlId{498}{\htmlClass{InductiveConstructor}{\text{NoConfidence}}}}\, \\ \,\htmlId{513}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$                 success (_ , Enact-NoConf)
    $\begin{pmatrix} \,\href{Ledger.Conway.Gov.Actions.html#745}{\htmlId{569}{\htmlClass{InductiveConstructor}{\text{UpdateCommittee}}}}\, \\ (\,\href{Ledger.Conway.Enact.Properties.html#588}{\htmlId{588}{\htmlClass{Bound}{\text{new}}}}\, , \,\href{Ledger.Conway.Enact.Properties.html#594}{\htmlId{594}{\htmlClass{Bound}{\text{rem}}}}\, , \,\href{Ledger.Conway.Enact.Properties.html#600}{\htmlId{600}{\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.Gov.Actions.html#780}{\htmlId{922}{\htmlClass{InductiveConstructor}{\text{NewConstitution}}}}\, \\ \,\htmlId{940}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$  success (-, Enact-NewConst)
    $\begin{pmatrix} \,\href{Ledger.Conway.Gov.Actions.html#815}{\htmlId{982}{\htmlClass{InductiveConstructor}{\text{TriggerHF}}}}\,       \\ \,\htmlId{1000}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$  success (-, Enact-HF)
    $\begin{pmatrix} \,\href{Ledger.Conway.Gov.Actions.html#850}{\htmlId{1036}{\htmlClass{InductiveConstructor}{\text{ChangePParams}}}}\,   \\ \,\htmlId{1054}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$  success (-, Enact-PParams)
    $\begin{pmatrix} \,\href{Ledger.Conway.Gov.Actions.html#920}{\htmlId{1095}{\htmlClass{InductiveConstructor}{\text{Info}}}}\,            \\ \,\htmlId{1113}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$  success (-, Enact-Info) 
    $\begin{pmatrix} \,\href{Ledger.Conway.Gov.Actions.html#885}{\htmlId{1152}{\htmlClass{InductiveConstructor}{\text{TreasuryWdrl}}}}\, \\ \,\href{Ledger.Conway.Enact.Properties.html#1167}{\htmlId{1167}{\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{1479}{\htmlClass{DottedPattern Symbol}{\text{.}}}\,\,\href{Ledger.Conway.Gov.Actions.html#710}{\htmlId{1480}{\htmlClass{DottedPattern InductiveConstructor}{\text{NoConfidence}}}}\,    \\ \,\htmlId{1498}{\htmlClass{Symbol}{\text{\_}}}\,               \end{pmatrix}$ | Enact-NoConf   = refl
  ... | $\begin{pmatrix} \,\htmlId{1552}{\htmlClass{DottedPattern Symbol}{\text{.}}}\,\,\href{Ledger.Conway.Gov.Actions.html#745}{\htmlId{1553}{\htmlClass{DottedPattern InductiveConstructor}{\text{UpdateCommittee}}}}\, \\ (\,\href{Ledger.Conway.Enact.Properties.html#1572}{\htmlId{1572}{\htmlClass{Bound}{\text{new}}}}\, , \,\href{Ledger.Conway.Enact.Properties.html#1578}{\htmlId{1578}{\htmlClass{Bound}{\text{rem}}}}\, , \,\href{Ledger.Conway.Enact.Properties.html#1584}{\htmlId{1584}{\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{1815}{\htmlClass{DottedPattern Symbol}{\text{.}}}\,\,\href{Ledger.Conway.Gov.Actions.html#780}{\htmlId{1816}{\htmlClass{DottedPattern InductiveConstructor}{\text{NewConstitution}}}}\, \\ \,\htmlId{1834}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$ | Enact-NewConst = refl
  ... | $\begin{pmatrix} \,\htmlId{1874}{\htmlClass{DottedPattern Symbol}{\text{.}}}\,\,\href{Ledger.Conway.Gov.Actions.html#815}{\htmlId{1875}{\htmlClass{DottedPattern InductiveConstructor}{\text{TriggerHF}}}}\,       \\ \,\htmlId{1893}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$ | Enact-HF       = refl
  ... | $\begin{pmatrix} \,\htmlId{1933}{\htmlClass{DottedPattern Symbol}{\text{.}}}\,\,\href{Ledger.Conway.Gov.Actions.html#850}{\htmlId{1934}{\htmlClass{DottedPattern InductiveConstructor}{\text{ChangePParams}}}}\,   \\ \,\htmlId{1952}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$ | Enact-PParams  = refl
  ... | $\begin{pmatrix} \,\htmlId{1992}{\htmlClass{DottedPattern Symbol}{\text{.}}}\,\,\href{Ledger.Conway.Gov.Actions.html#920}{\htmlId{1993}{\htmlClass{DottedPattern InductiveConstructor}{\text{Info}}}}\,            \\ \,\htmlId{2011}{\htmlClass{Symbol}{\text{\_}}}\, \end{pmatrix}$ | Enact-Info     = refl
  ... | $\begin{pmatrix} \,\htmlId{2051}{\htmlClass{DottedPattern Symbol}{\text{.}}}\,\,\href{Ledger.Conway.Gov.Actions.html#885}{\htmlId{2052}{\htmlClass{DottedPattern InductiveConstructor}{\text{TreasuryWdrl}}}}\, \\ \,\href{Ledger.Conway.Enact.Properties.html#2067}{\htmlId{2067}{\htmlClass{Bound}{\text{wdrl}}}}\, \end{pmatrix}$ | Enact-Wdrl p
    rewrite dec-yes (¿ ∑[ x  s .withdrawals ∪⁺ wdrl ] x  EnactEnv.treasury Γᵉ ¿) p .proj₂
    = refl