import Mathlib
import Development.AbelianVarietyTheory.Definitions.Divisors.DivisorSupportCondition
import Development.AbelianVarietyTheory.Definitions.Divisors.SecClass
import Development.AbelianVarietyTheory.Proofs.DivisorProofs.IsZeroChains

open CategoryTheory Limits AlgebraicGeometry Opposite CochainComplex CochainComplex.HomComplex GlobalTheory.EtC

namespace GlobalTheory.EtC

open CategoryTheory Limits AlgebraicGeometry Opposite CochainComplex CochainComplex.HomComplex in

theorem _root_.GlobalTheory.EtC.free_hom_sections : ∀ (R : Type) [CommRing R] (P : _root_.GlobalTheory.EtC.PSh)
    (F : _root_.GlobalTheory.EtC.Shv R),
    (∀ a : ∀ U : Scheme.{0}, P.obj (op U) → _root_.GlobalTheory.EtC.Sec F U,
      (∀ (V U : Scheme.{0}) (g : V ⟶ U) x,
        _root_.GlobalTheory.EtC.Sec.res g (a U x) = a V (P.map g.op x)) →
      ∃ φ : (_root_.GlobalTheory.EtC.free R).obj P ⟶ F, ∀ U x,
        _root_.GlobalTheory.EtC.Sec.map φ (_root_.GlobalTheory.EtC.freeGen R P U x) = a U x) ∧
    (∀ φ ψ : (_root_.GlobalTheory.EtC.free R).obj P ⟶ F,
      (∀ U x, _root_.GlobalTheory.EtC.Sec.map φ (_root_.GlobalTheory.EtC.freeGen R P U x) =
        _root_.GlobalTheory.EtC.Sec.map ψ (_root_.GlobalTheory.EtC.freeGen R P U x)) → φ = ψ) ∧
    (∀ (V U : Scheme.{0}) (g : V ⟶ U) x,
      _root_.GlobalTheory.EtC.Sec.res g (_root_.GlobalTheory.EtC.freeGen R P U x) =
        _root_.GlobalTheory.EtC.freeGen R P V (P.map g.op x)) ∧
    ∀ (Q : _root_.GlobalTheory.EtC.PSh) (f : P ⟶ Q) U x,
      _root_.GlobalTheory.EtC.Sec.map ((_root_.GlobalTheory.EtC.free R).map f)
          (_root_.GlobalTheory.EtC.freeGen R P U x) =
        _root_.GlobalTheory.EtC.freeGen R Q U (f.app (op U) x) := by
  intro R _ P F
  exact ⟨fun a ha => _root_.GlobalTheory.EtC.CupSpec.free_exists P F a ha,
    fun φ ψ h => _root_.GlobalTheory.EtC.CupSpec.free_ext φ ψ h,
    fun V U g x => _root_.GlobalTheory.EtC.CupSpec.freeGen_res P g x,
    fun Q f U x => _root_.GlobalTheory.EtC.CupSpec.freeGen_map f U x⟩

end GlobalTheory.EtC
