{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://developer.reits.tech/schemas/d06-browser-auth-pre-admission.v1.schema.json",
  "title": "D06 Browser Auth SDK / BFF source-bound pre-admission",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "$schema",
    "schemaVersion",
    "observedAt",
    "status",
    "planBinding",
    "program",
    "knife",
    "sourceSnapshot",
    "foundationSignals",
    "currentFindings",
    "admissionGates",
    "admissionSummary",
    "targetArchitecture",
    "targetSurfaces",
    "realStateContract",
    "negativeTests",
    "migrationLanes",
    "activationContract",
    "invariants",
    "boundary"
  ],
  "properties": {
    "$schema": {
      "const": "/schemas/d06-browser-auth-pre-admission.v1.schema.json"
    },
    "schemaVersion": {
      "const": "developer.reits.tech/d06-browser-auth-pre-admission/v1"
    },
    "observedAt": {
      "type": "string",
      "format": "date-time"
    },
    "status": {
      "const": "D06_PRE_ADMISSION_REPOSITORY_IMPLEMENTED_D05_AND_BROWSER_AUTH_GATES_BLOCKED"
    },
    "planBinding": {
      "type": "object",
      "additionalProperties": false,
      "required": ["planId", "sha256"],
      "properties": {
        "planId": {
          "const": "D06-P0-BROWSER-AUTH-SDK-BFF-PRE-ADMISSION-V1"
        },
        "sha256": {
          "const": "0ed97d8a0844b5db0a2c8fa1c40cbcf7630f693ab3d46b9dcfcded4f28af1dc9"
        }
      }
    },
    "program": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "totalKnives",
        "acceptedKnives",
        "currentOrdinal",
        "currentKnife",
        "candidateKnife",
        "remainingIncludingCurrent",
        "remainingAfterD05",
        "d05Accepted",
        "d06Activated",
        "ledgerAdvanced"
      ],
      "properties": {
        "totalKnives": { "const": 36 },
        "acceptedKnives": { "const": 4 },
        "currentOrdinal": { "const": 5 },
        "currentKnife": { "const": "D05" },
        "candidateKnife": { "const": "D06" },
        "remainingIncludingCurrent": { "const": 32 },
        "remainingAfterD05": { "const": 31 },
        "d05Accepted": { "const": false },
        "d06Activated": { "const": false },
        "ledgerAdvanced": { "const": false }
      }
    },
    "knife": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "title",
        "kind",
        "owner",
        "repositoryImplementationComplete",
        "countsAsProgramAcceptance",
        "nextExecutableTask",
        "activationRequires"
      ],
      "properties": {
        "id": { "const": "D06-P0" },
        "title": { "type": "string", "minLength": 10 },
        "kind": { "const": "PRE_ADMISSION" },
        "owner": { "type": "string", "minLength": 10 },
        "repositoryImplementationComplete": { "const": true },
        "countsAsProgramAcceptance": { "const": false },
        "nextExecutableTask": { "const": "D05-T02" },
        "activationRequires": { "const": "D05_ACCEPTED_AND_LEDGER_CAS_TO_D06" }
      }
    },
    "sourceSnapshot": {
      "type": "object",
      "additionalProperties": false,
      "required": ["repositoriesFetched", "repositories"],
      "properties": {
        "repositoriesFetched": { "const": 4 },
        "repositories": {
          "type": "array",
          "minItems": 4,
          "maxItems": 4,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["id", "revision", "branch", "dirtyFiles", "evidence"],
            "properties": {
              "id": {
                "enum": [
                  "reits-auth",
                  "miniapp-open-platform",
                  "public-booking-platform",
                  "opensdk"
                ]
              },
              "revision": {
                "type": "string",
                "pattern": "^[0-9a-f]{40}$"
              },
              "branch": { "const": "main" },
              "dirtyFiles": { "const": 0 },
              "evidence": {
                "type": "array",
                "minItems": 1,
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["path", "gitBlob", "finding"],
                  "properties": {
                    "path": { "type": "string", "minLength": 3 },
                    "gitBlob": {
                      "type": "string",
                      "pattern": "^[0-9a-f]{40}$"
                    },
                    "finding": { "type": "string", "minLength": 20 }
                  }
                }
              }
            }
          }
        }
      }
    },
    "foundationSignals": {
      "type": "array",
      "minItems": 3,
      "maxItems": 3,
      "items": { "$ref": "#/$defs/statusCard" }
    },
    "currentFindings": {
      "type": "array",
      "minItems": 5,
      "maxItems": 5,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "severity",
          "title",
          "repository",
          "observed",
          "target",
          "state"
        ],
        "properties": {
          "id": { "pattern": "^AUTH-[0-9]{2}$" },
          "severity": { "enum": ["CRITICAL", "HIGH"] },
          "title": { "type": "string", "minLength": 8 },
          "repository": { "type": "string", "minLength": 3 },
          "observed": { "type": "string", "minLength": 3 },
          "target": { "type": "string", "minLength": 20 },
          "state": { "const": "BLOCKED" }
        }
      }
    },
    "admissionGates": {
      "type": "array",
      "minItems": 10,
      "maxItems": 10,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "title", "owner", "observed", "state"],
        "properties": {
          "id": { "pattern": "^D06-A(0[1-9]|10)$" },
          "title": { "type": "string", "minLength": 8 },
          "owner": { "type": "string", "minLength": 3 },
          "observed": { "type": "string", "minLength": 2 },
          "state": { "const": "DENIED" }
        }
      }
    },
    "admissionSummary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "required",
        "satisfied",
        "denied",
        "sourceRepositories",
        "targetSurfaces",
        "realStatesPerSurface",
        "requiredStateReceipts",
        "observedStateReceipts",
        "localStorageTokenOperations"
      ],
      "properties": {
        "required": { "const": 10 },
        "satisfied": { "const": 0 },
        "denied": { "const": 10 },
        "sourceRepositories": { "const": 4 },
        "targetSurfaces": { "const": 3 },
        "realStatesPerSurface": { "const": 9 },
        "requiredStateReceipts": { "const": 27 },
        "observedStateReceipts": { "const": 0 },
        "localStorageTokenOperations": { "const": 16 }
      }
    },
    "targetArchitecture": {
      "type": "array",
      "minItems": 7,
      "maxItems": 7,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "ordinal",
          "id",
          "component",
          "contract",
          "responsibility"
        ],
        "properties": {
          "ordinal": { "type": "integer", "minimum": 1, "maximum": 7 },
          "id": { "type": "string", "minLength": 3 },
          "component": { "type": "string", "minLength": 3 },
          "contract": { "type": "string", "minLength": 3 },
          "responsibility": { "type": "string", "minLength": 20 }
        }
      }
    },
    "targetSurfaces": {
      "type": "array",
      "minItems": 3,
      "maxItems": 3,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "title",
          "repository",
          "current",
          "target",
          "primaryAction",
          "secondaryAction"
        ],
        "properties": {
          "id": { "pattern": "^AUTH-S0[1-3]$" },
          "title": { "type": "string", "minLength": 8 },
          "repository": { "type": "string", "minLength": 3 },
          "current": { "type": "string", "minLength": 10 },
          "target": { "type": "string", "minLength": 20 },
          "primaryAction": { "type": "string", "minLength": 3 },
          "secondaryAction": { "type": "string", "minLength": 3 }
        }
      }
    },
    "realStateContract": {
      "type": "array",
      "minItems": 9,
      "maxItems": 9,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "regionChange"],
        "properties": {
          "id": {
            "enum": [
              "READY",
              "LOADING",
              "EMPTY",
              "PARTIAL_ERROR",
              "ERROR",
              "OFFLINE",
              "FORBIDDEN",
              "CONFIRM",
              "SUCCESS"
            ]
          },
          "regionChange": { "type": "string", "minLength": 20 }
        }
      }
    },
    "negativeTests": {
      "type": "array",
      "minItems": 12,
      "maxItems": 12,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "pattern": "^[a-z][a-z0-9_]+$"
      }
    },
    "migrationLanes": {
      "type": "array",
      "minItems": 4,
      "maxItems": 4,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["repository", "owner", "deliverable", "state"],
        "properties": {
          "repository": { "type": "string", "minLength": 3 },
          "owner": { "type": "string", "minLength": 3 },
          "deliverable": { "type": "string", "minLength": 20 },
          "state": { "const": "WAIT_D05" }
        }
      }
    },
    "activationContract": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "requiredD05AcceptanceReceipts",
        "observedD05AcceptanceReceipts",
        "requiredLedgerCasReceipts",
        "observedLedgerCasReceipts",
        "requiredAdmissionGates",
        "observedAdmissionGates",
        "requiredStateReceipts",
        "observedStateReceipts",
        "d06ActivationAuthorized",
        "externalWritesExecuted"
      ],
      "properties": {
        "requiredD05AcceptanceReceipts": { "const": 1 },
        "observedD05AcceptanceReceipts": { "const": 0 },
        "requiredLedgerCasReceipts": { "const": 1 },
        "observedLedgerCasReceipts": { "const": 0 },
        "requiredAdmissionGates": { "const": 10 },
        "observedAdmissionGates": { "const": 0 },
        "requiredStateReceipts": { "const": 27 },
        "observedStateReceipts": { "const": 0 },
        "d06ActivationAuthorized": { "const": false },
        "externalWritesExecuted": { "const": 0 }
      }
    },
    "invariants": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "repositoryDiscoveryComplete",
        "targetUiDefined",
        "admissionVerifierDefined",
        "browserTokensRemoved",
        "d05Accepted",
        "d06Activated",
        "programAdvanced"
      ],
      "properties": {
        "repositoryDiscoveryComplete": { "const": true },
        "targetUiDefined": { "const": true },
        "admissionVerifierDefined": { "const": true },
        "browserTokensRemoved": { "const": false },
        "d05Accepted": { "const": false },
        "d06Activated": { "const": false },
        "programAdvanced": { "const": false }
      }
    },
    "boundary": {
      "type": "string",
      "minLength": 100
    }
  },
  "$defs": {
    "statusCard": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "title", "repository", "state"],
      "properties": {
        "id": { "pattern": "^FOUNDATION-[0-9]{2}$" },
        "title": { "type": "string", "minLength": 8 },
        "repository": { "type": "string", "minLength": 3 },
        "state": { "pattern": "^OBSERVED_" }
      }
    }
  }
}
