{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://education.gov.uk/fostering/schemas/fostering-submission-response.schema.json",
  "title": "Fostering Monthly Submission Response",
  "description": "Response payload returned by the monthly fostering submission endpoint for accepted submissions, validation failures, and non-blocking warnings.",
  "oneOf": [
    {
      "$ref": "#/$defs/submissionAcceptedResponse"
    },
    {
      "$ref": "#/$defs/validationErrorResponse"
    }
  ],
  "$defs": {
    "validationSeverity": {
      "type": "integer",
      "enum": [
        0,
        1
      ],
      "description": "Validation severity as currently serialized by the API. 0 = Error, 1 = Warning."
    },
    "validationIssue": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "code",
        "severity",
        "path",
        "message"
      ],
      "properties": {
        "code": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100,
          "description": "Stable validation code such as VAL-04 or INVALID_JSON."
        },
        "severity": {
          "$ref": "#/$defs/validationSeverity"
        },
        "path": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500,
          "description": "JSON path or field path associated with the issue."
        },
        "message": {
          "type": "string",
          "minLength": 1,
          "maxLength": 4000,
          "description": "Human-readable validation message."
        },
        "application_unique_identifier": {
          "description": "Application-level unique identifier when the issue relates to a specific application item; otherwise null or omitted.",
          "oneOf": [
            {
              "type": "string",
              "format": "uuid"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "submissionAcceptedResponse": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "message"
      ],
      "properties": {
        "message": {
          "type": "string",
          "const": "Submission accepted for processing."
        },
        "submission_id": {
          "description": "Submission identifier when present in the request; otherwise null or omitted.",
          "oneOf": [
            {
              "type": "string",
              "format": "uuid"
            },
            {
              "type": "null"
            }
          ]
        },
        "warnings": {
          "type": "array",
          "description": "Non-blocking validation warnings returned with an accepted submission.",
          "items": {
            "$ref": "#/$defs/validationIssue"
          }
        }
      }
    },
    "validationErrorResponse": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "message",
        "errors"
      ],
      "properties": {
        "message": {
          "type": "string",
          "const": "Validation failed."
        },
        "errors": {
          "type": "array",
          "minItems": 1,
          "description": "Blocking validation issues that prevent the submission from being accepted.",
          "items": {
            "$ref": "#/$defs/validationIssue"
          }
        },
        "warnings": {
          "type": "array",
          "description": "Non-blocking validation warnings returned alongside blocking issues when applicable.",
          "items": {
            "$ref": "#/$defs/validationIssue"
          }
        }
      }
    }
  }
}
