{-# OPTIONS --without-K --exact-split --two-level #-}

--------------------------------------------------------------------------------
-- Theorem 5.15, the complete cycle, for a general path interval.
--
-- For a path interval presented by a `PathStructure` (the interface of
-- Lemma 5.8; not necessarily fibrant), with boundary inclusion iβˆ‚ a
-- full 2LTT cofibration, the fibration half `cof` plus the trivial half
-- `triv` (relative funext); no cofibrancy of I or βˆ‚I is assumed, conditions
-- (1) univalence, (4) a homotopy coherent Glue structure for (iβˆ‚, 𝓀), and (5)
-- a weak Glue structure for (I, 0, 1, 𝓀) are inter-derivable:
--
--   1β‡’4  `GlueSandwich.ua-homotopy-coherent-glue`;
--   4β‡’5  `GlueStrengthChain3.strength-chain-3`;
--   5β‡’1  `CoercionLaws.general-weak-glue-implies-ua` (Theorem 5.14
--        with the coercion laws derived from the path presentation).
--
-- Unlike `GlueSandwichComplete`, this does not assume the interval is fibrant:
-- the coercion laws come from the path presentation (`PathStructure`) rather
-- than from a segment transport.
--------------------------------------------------------------------------------

module Extension.GlueSandwichGeneral where

open import Extension.Prelude
open import Extension.CofibFibration using (is-cofib)
open import Extension.RelFunext using (satisfies-rel-funext)
open import Extension.GlueStructure using (has-homotopy-coherent-glue)
open import Extension.GlueRules using (WeakGlue)
open import Extension.GlueSandwich using (ua-homotopy-coherent-glue)
open import Extension.GlueStrengthChain3 using (strength-chain-3)
open import Extension.CoercionLaws using (PathStructure ; general-weak-glue-implies-ua)

private
  variable
    β„“I 𝓀 : Level

-- Boundary inclusion of the path interval: βˆ‚I = ⊀ + ⊀ β†’ I, hitting the endpoints.
iβˆ‚ : (P : PathStructure β„“I 𝓀) β†’ (βŠ€α΅‰ {β„“I} +ᡉ βŠ€α΅‰ {β„“I}) β†’ PathStructure.I P
iβˆ‚ P (inlᡉ _) = PathStructure.0I P
iβˆ‚ P (inrᡉ _) = PathStructure.1I P

module _ (P : PathStructure β„“I 𝓀)
         (cof  : is-cofib (iβˆ‚ P) (lsuc 𝓀))
         (triv : satisfies-rel-funext cof)
       where

  Cond1 : UU (lsuc 𝓀)
  Cond1 = (A B : UU 𝓀) β†’ isEquiv (idtoeqv {A = A} {B = B})

  Cond4 : UUᡉ (lsuc 𝓀 βŠ” β„“I)
  Cond4 = has-homotopy-coherent-glue (iβˆ‚ P) 𝓀

  Cond5 : UUᡉ (β„“I βŠ” lsuc 𝓀)
  Cond5 = WeakGlue (PathStructure.I P) (PathStructure.0I P) (PathStructure.1I P) 𝓀

  1β‡’4 : Cond1 β†’ Cond4
  1β‡’4 U = ua-homotopy-coherent-glue U cof triv

  4β‡’5 : Cond4 β†’ Cond5
  4β‡’5 hcg = strength-chain-3 (PathStructure.I P) (iβˆ‚ P) 𝓀 hcg

  5β‡’1 : Cond5 β†’ Cond1
  5β‡’1 = general-weak-glue-implies-ua P

  -- The complete cycle for a general path interval.
  glue-sandwich : (Cond1 β†’ Cond4) ×ᡉ ((Cond4 β†’ Cond5) ×ᡉ (Cond5 β†’ Cond1))
  glue-sandwich = 1β‡’4 ,ᡉ (4β‡’5 ,ᡉ 5β‡’1)