{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://scoperail.fokalabs.io/method/ticket-proposal.schema.json",
  "title": "ScopeRail ticket proposal",
  "description": "A user-reviewable support or engineering ticket draft. Drafting and submission remain separate operations.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "status",
    "requester",
    "context",
    "title",
    "summary",
    "observedBehavior",
    "expectedOutcome",
    "evidenceRefs",
    "missingInformation",
    "userConfirmed",
    "createdAt"
  ],
  "properties": {
    "id": {
      "type": "string",
      "minLength": 8,
      "maxLength": 160
    },
    "status": {
      "type": "string",
      "enum": [
        "draft",
        "reviewed",
        "submitted",
        "cancelled"
      ]
    },
    "requester": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "subjectRef"
      ],
      "properties": {
        "subjectRef": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "contactRef": {
          "type": "string",
          "maxLength": 200
        }
      }
    },
    "context": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "currentSurface"
      ],
      "properties": {
        "currentSurface": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "routeRef": {
          "type": "string",
          "maxLength": 300
        },
        "scopeRefs": {
          "type": "array",
          "maxItems": 24,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          }
        },
        "environment": {
          "type": "string",
          "maxLength": 240
        }
      }
    },
    "title": {
      "type": "string",
      "minLength": 5,
      "maxLength": 180
    },
    "summary": {
      "type": "string",
      "minLength": 10,
      "maxLength": 2000
    },
    "observedBehavior": {
      "type": "string",
      "minLength": 3,
      "maxLength": 3000
    },
    "expectedOutcome": {
      "type": "string",
      "minLength": 3,
      "maxLength": 2000
    },
    "reproductionSteps": {
      "type": "array",
      "maxItems": 24,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 500
      }
    },
    "impact": {
      "type": "string",
      "maxLength": 1000
    },
    "evidenceRefs": {
      "type": "array",
      "maxItems": 64,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 240
      }
    },
    "missingInformation": {
      "type": "array",
      "maxItems": 24,
      "items": {
        "type": "string",
        "minLength": 2,
        "maxLength": 500
      }
    },
    "userConfirmed": {
      "type": "boolean"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "submittedAt": {
      "type": "string",
      "format": "date-time"
    },
    "submittedTicketRef": {
      "type": "string",
      "maxLength": 240
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "status": {
            "const": "submitted"
          }
        },
        "required": [
          "status"
        ]
      },
      "then": {
        "properties": {
          "userConfirmed": {
            "const": true
          }
        },
        "required": [
          "submittedAt",
          "submittedTicketRef"
        ]
      }
    }
  ]
}
