-- t-paliad-182 / Fristen Phase 3 Slice 1 — paliad.projects.instance_level
-- (design §2.7, §7).
--
-- Lets the SmartTimeline + calculator derive the effective proceeding
-- code from (proceeding_code, instance_level) — e.g. DE_INF + 'appeal'
-- resolves to DE_INF_OLG.
--
-- Nullable: NULL means "not asked / not relevant" (e.g. EP_GRANT, a
-- non-litigation patent project). Allowed values:
--   first       — first instance (default once the picker UI lands)
--   appeal      — Berufung / EPA Beschwerde / appellate level
--   cassation   — BGH-Revision / EPA-EBA / final instance
--
-- No backfill in this slice. The picker UI (Slice 8) writes the column;
-- legacy projects stay NULL and behave as if first instance via the
-- calculator's fallback (`NULL OR 'first'` → use base proceeding code).
--
-- Idempotent: re-applying is a no-op. Tracker advances 79 → 80.

ALTER TABLE paliad.projects
    ADD COLUMN IF NOT EXISTS instance_level text
        CHECK (instance_level IS NULL
               OR instance_level IN ('first', 'appeal', 'cassation'));

COMMENT ON COLUMN paliad.projects.instance_level IS
    'Procedural instance the project sits at: first | appeal | '
    'cassation. NULL = unset / not applicable. Combined with '
    'proceeding_type.code + jurisdiction by FristenrechnerService to '
    'pick the effective proceeding code (e.g. DE_INF + appeal → '
    'DE_INF_OLG). See design-fristen-phase2-2026-05-15.md §2.7, §7.';
