import FoundationalReformulation.Context

namespace FoundationalReformulation

open CategoryTheory

universe v u w

/-- Local data, its compatibility condition, and a restriction map for a chosen cover. -/
structure DescentData {C : Type u} [Category.{v} C] (target : C) where
  cover : Cover.{v, u, w} target
  LocalData : Type w
  compatible : LocalData → Prop
  GlobalData : Type w
  restrict : GlobalData → {item // compatible item}

/-- Explicit evidence that compatible local data and global data are equivalent. -/
structure EffectiveDescent {C : Type u} [Category.{v} C] {target : C}
    (data : DescentData.{v, u, w} target) where
  equivalence : data.GlobalData ≃ {item // data.compatible item}
  agreesWithRestriction : (global : data.GlobalData) →
    equivalence global = data.restrict global

def EffectiveDescent.reconstruct {C : Type u} [Category.{v} C] {target : C}
    {data : DescentData.{v, u, w} target} (witness : EffectiveDescent data)
    (item : {value // data.compatible value}) : data.GlobalData :=
  witness.equivalence.symm item

theorem EffectiveDescent.restrict_reconstruct {C : Type u} [Category.{v} C]
    {target : C} {data : DescentData.{v, u, w} target}
    (witness : EffectiveDescent data) (item : {value // data.compatible value}) :
    data.restrict (witness.reconstruct item) = item :=
  (witness.agreesWithRestriction (witness.reconstruct item)).symm.trans
    (witness.equivalence.apply_symm_apply item)

structure P1C02Dependencies (assumptions : ContextAssumptions) : Prop where
  p1a02 : assumptions.p1a02_coverageStableUnderBaseChange
  p1a03 : assumptions.p1a03_coefficientAssignment
  p1a04 : assumptions.p1a04_effectiveDescentClass

namespace DescentClaims

def effectiveDescent : ClaimRecord :=
  .openGoal "P1-C02" ["P1-A02", "P1-A03", "P1-A04"]

end DescentClaims

end FoundationalReformulation
