{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://education.gov.uk/fostering/schemas/fostering-submission.schema.json",
  "title": "Fostering Monthly Submission",
  "description": "Combined monthly fostering submission payload containing caller-supplied metadata, aggregate hub return data, and application-level data. Trusted submitter context is supplied separately via the x-subscription-id request header and is not part of the JSON body.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "submission"
  ],
  "properties": {
    "submission": {
      "$ref": "#/$defs/submission"
    }
  },
  "$defs": {
    "submission": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "metadata",
        "aggregate_data",
        "applications"
      ],
      "properties": {
        "metadata": {
          "$ref": "#/$defs/metadata"
        },
        "aggregate_data": {
          "$ref": "#/$defs/aggregateData"
        },
        "applications": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/application"
          }
        }
      }
    },
    "metadata": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "reporting_period"
      ],
      "properties": {
        "reporting_period": {
          "type": "string",
          "pattern": "^\\d{4}-(0[1-9]|1[0-2])$",
          "description": "Monthly reporting period in YYYY-MM format. Submission identity, hub mapping, caller identity, and source are derived from the trusted x-subscription-id header/context rather than the payload."
        },
        "notes": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 2000
        }
      }
    },
    "aggregateData": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "monthly_household_approval",
        "monthly_fc_places_approval",
        "monthly_fc_capacity_total",
        "monthly_fc_deregistered_total"
      ],
      "properties": {
        "monthly_household_approval": {
          "type": "integer",
          "minimum": 0
        },
        "monthly_fc_places_approval": {
          "type": "integer",
          "minimum": 0
        },
        "monthly_fc_capacity_total": {
          "type": "integer",
          "minimum": 0
        },
        "monthly_fc_deregistered_total": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "application": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "unique_identifier",
        "enquiry_date"
      ],
      "properties": {
        "unique_identifier": {
          "type": "string",
          "format": "uuid"
        },
        "enquiry_date": {
          "type": "string",
          "format": "date"
        },
        "enquiry_source": {
          "$ref": "#/$defs/enquirySourceCode"
        },
        "enquiry_source_other": {
          "type": "string",
          "maxLength": 250
        },
        "withdrawn_date": {
          "type": "string",
          "format": "date"
        },
        "withdrawal_reason": {
          "$ref": "#/$defs/withdrawalReasonCode"
        },
        "withdrawal_reason_other": {
          "type": "string",
          "maxLength": 250
        },
        "rejection_date": {
          "type": "string",
          "format": "date"
        },
        "rejection_reason": {
          "$ref": "#/$defs/rejectionReasonCode"
        },
        "rejection_reason_other": {
          "type": "string",
          "maxLength": 250
        },
        "eoi_date": {
          "type": "string",
          "format": "date"
        },
        "initial_visit_date": {
          "type": "string",
          "format": "date"
        },
        "application_start_date": {
          "type": "string",
          "format": "date"
        },
        "panel_date": {
          "type": "string",
          "format": "date"
        },
        "approval_date": {
          "type": "string",
          "format": "date"
        },
        "responsible_la_code": {
          "type": "string",
          "maxLength": 9
        },
        "foster_carer_places_per_approval": {
          "type": "integer",
          "minimum": 1,
          "maximum": 3
        },
        "type_of_place": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/typeOfPlaceCode"
          }
        },
        "type_of_place_other": {
          "type": "string",
          "maxLength": 250
        },
        "deregistration_date": {
          "type": "string",
          "format": "date"
        },
        "deregistration_reason": {
          "$ref": "#/$defs/deregistrationReasonCode"
        },
        "deregistration_reason_other": {
          "type": "string",
          "maxLength": 250
        },
        "foster_carers": {
          "type": "array",
          "maxItems": 2,
          "items": {
            "$ref": "#/$defs/fosterCarer"
          }
        }
      },
      "description": "Conditional dependencies, lookup/reference checks, trusted subscription-context checks, and cross-field date ordering rules are enforced by the validation endpoint after structural schema validation."
    },
    "enquirySourceCode": {
      "type": "string",
      "description": "Controlled code for where the prospective foster carer found out about fostering.",
      "enum": [
        "NATIONAL_CAMPAIGN",
        "WEBSITE",
        "EVENT",
        "SOCIAL_MEDIA",
        "REFERRAL",
        "OTHER"
      ]
    },
    "withdrawalReasonCode": {
      "type": "string",
      "description": "Controlled code for the reason an applicant withdrew their application.",
      "enum": [
        "PERSONAL_CIRCUMSTANCES",
        "ASSESSMENT_CONCERNS",
        "NOT_READY",
        "HEALTH",
        "FINANCIAL",
        "PROPERTY_NOT_SUITABLE",
        "CHOSE_IFA",
        "CHOSE_ADOPTION",
        "SGO_OR_STAYING_PUT",
        "OTHER"
      ]
    },
    "rejectionReasonCode": {
      "type": "string",
      "description": "Controlled code for the reason a hub did not progress an application.",
      "enum": [
        "PROPERTY_NOT_SUITABLE",
        "NOT_CONTACTABLE",
        "DUPLICATE",
        "SAFEGUARDING_CONCERN",
        "ELIGIBILITY",
        "REFERENCE_INADEQUATE",
        "ASSESSMENT_CONCERNS",
        "FAMILY_DYNAMICS",
        "HEALTH",
        "LEGAL_STATUS",
        "OTHER"
      ]
    },
    "typeOfPlaceCode": {
      "type": "string",
      "description": "Controlled code for the type of foster placement approved.",
      "enum": [
        "LONG_TERM",
        "SHORT_TERM",
        "SHORT_BREAKS_AND_RESPITE",
        "EMERGENCY",
        "PARENT_AND_CHILD",
        "SPECIALIST",
        "REMAND",
        "FOSTERING_TO_ADOPT",
        "OTHER"
      ]
    },
    "deregistrationReasonCode": {
      "type": "string",
      "description": "Controlled code for the reason a household deregistered from fostering.",
      "enum": [
        "CHILD_PLACED_WITH_FAMILY",
        "TRANSFERRED_TO_IFA",
        "INITIATED_BY_FOSTERING_SERVICE",
        "TRANSFERRED_TO_LA",
        "CARER_RETIREMENT",
        "DISSATISFACTION_WITH_FOSTERING",
        "HEALTH_REASONS",
        "MOVED_AWAY",
        "NATURAL_EXPIRY",
        "CARER_CEASED_FOSTERING",
        "OTHER"
      ]
    },
    "fosterCarerAgeCode": {
      "type": "string",
      "description": "Controlled code for foster carer age band.",
      "enum": [
        "18_19",
        "20_24",
        "25_29",
        "30_34",
        "35_39",
        "40_44",
        "45_49",
        "50_54",
        "55_59",
        "60_64",
        "65+",
        "PREFER_NOT_TO_SAY"
      ]
    },
    "fosterCarerEthnicityCode": {
      "type": "string",
      "description": "Controlled code for foster carer ethnicity.",
      "enum": [
        "ASIAN_BANGLADESHI",
        "ASIAN_CHINESE",
        "ASIAN_INDIAN",
        "ASIAN_PAKISTANI",
        "ASIAN_OTHER",
        "BLACK_AFRICAN",
        "BLACK_CARIBBEAN",
        "BLACK_OTHER",
        "MIXED_WHITE_ASIAN",
        "MIXED_WHITE_BLACK_AFRICAN",
        "MIXED_WHITE_BLACK_CARIBBEAN",
        "MIXED_OTHER",
        "WHITE_BRITISH",
        "WHITE_IRISH",
        "WHITE_GYPSY_TRAVELLER",
        "WHITE_ROMA",
        "WHITE_OTHER",
        "OTHER_ARAB",
        "OTHER_ANY",
        "PREFER_NOT_TO_SAY"
      ]
    },
    "fosterCarerSexCode": {
      "type": "string",
      "description": "Controlled code for foster carer sex.",
      "enum": [
        "MALE",
        "FEMALE",
        "PREFER_NOT_TO_SAY"
      ]
    },
    "fosterCarerReligionCode": {
      "type": "string",
      "description": "Controlled code for foster carer religion.",
      "enum": [
        "NO_RELIGION",
        "CHRISTIAN",
        "BUDDHIST",
        "HINDU",
        "JEWISH",
        "MUSLIM",
        "SIKH",
        "OTHER_RELIGION",
        "PREFER_NOT_TO_SAY"
      ]
    },
    "fosterCarerSexualityCode": {
      "type": "string",
      "description": "Controlled code for foster carer sexuality.",
      "enum": [
        "STRAIGHT_HETEROSEXUAL",
        "GAY_OR_LESBIAN",
        "BISEXUAL",
        "OTHER_ORIENTATION",
        "PREFER_NOT_TO_SAY"
      ]
    },
    "fosterCarerDisabilityCode": {
      "type": "string",
      "description": "Controlled code for foster carer disability status.",
      "enum": [
        "DISABLED",
        "NOT_DISABLED",
        "PREFER_NOT_TO_SAY"
      ]
    },
    "fosterCarer": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "carer_position"
      ],
      "properties": {
        "carer_position": {
          "type": "integer",
          "enum": [
            1,
            2
          ]
        },
        "age": {
          "$ref": "#/$defs/fosterCarerAgeCode"
        },
        "ethnicity": {
          "$ref": "#/$defs/fosterCarerEthnicityCode"
        },
        "sex": {
          "$ref": "#/$defs/fosterCarerSexCode"
        },
        "religion": {
          "$ref": "#/$defs/fosterCarerReligionCode"
        },
        "sexuality": {
          "$ref": "#/$defs/fosterCarerSexualityCode"
        },
        "disability": {
          "$ref": "#/$defs/fosterCarerDisabilityCode"
        }
      }
    }
  }
}
