{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/declararfacil-com/json-schema/declararfacil-com-historical-modelo-input-schema.json",
  "title": "HistoricalModeloInput",
  "x-generated": "2026-11-05",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/declararfacil-com-openapi.json#/components/schemas/HistoricalModeloInput",
  "type": "object",
  "required": [
    "modelo",
    "year"
  ],
  "properties": {
    "modelo": {
      "type": "string",
      "enum": [
        "303",
        "130",
        "349"
      ]
    },
    "year": {
      "type": "integer"
    },
    "quarter": {
      "type": "integer",
      "minimum": 1,
      "maximum": 4
    },
    "sourceType": {
      "type": "string",
      "enum": [
        "UPLOADED_FORM",
        "MANUAL_ENTRY"
      ],
      "default": "UPLOADED_FORM",
      "description": "UPLOADED_FORM when read from a filed form, MANUAL_ENTRY when typed from the user's notes"
    },
    "casillas": {
      "type": "object",
      "description": "Every box printed on the form, keyed by its printed two- or three-digit number ('01', '71', '110', '120'). Monetary amounts in EUR; rate boxes in percent. Omitted keys preserve existing values, null clears, zero is stored. 130 boxes are cumulative. Aggregate aliases must agree with the same submitted box",
      "additionalProperties": {
        "type": [
          "number",
          "null"
        ]
      }
    },
    "nif": {
      "type": [
        "string",
        "null"
      ]
    },
    "apellidosNombre": {
      "type": [
        "string",
        "null"
      ]
    },
    "numeroJustificante": {
      "type": [
        "string",
        "null"
      ],
      "description": "AEAT receipt number exactly as printed; does not itself mark a filing as verified"
    },
    "sourceDocumentUrl": {
      "type": [
        "string",
        "null"
      ]
    },
    "filed": {
      "type": "boolean",
      "description": "Explicit assertion that this source was filed with AEAT. Separate from internal verified status. Omitted means unknown."
    },
    "datosExtraidos": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": true,
      "description": "Original extraction retained for provenance; does not populate boxes automatically. Replay casillas explicitly to repair an earlier import."
    },
    "period": {
      "type": "string",
      "description": "349 only: 1T..4T or 01..12. May use quarter for quarterly forms."
    },
    "operacionesIntracomunitarias": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "pais",
          "vatIdEU",
          "nombreOperador",
          "clave",
          "baseImponible"
        ],
        "properties": {
          "pais": {
            "type": "string"
          },
          "vatIdEU": {
            "type": "string"
          },
          "nombreOperador": {
            "type": "string"
          },
          "clave": {
            "type": "string"
          },
          "baseImponible": {
            "type": "number"
          },
          "rectificaciones": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          }
        }
      }
    },
    "totalOperaciones": {
      "type": [
        "integer",
        "null"
      ]
    },
    "importeTotalOperaciones": {
      "type": [
        "number",
        "null"
      ]
    },
    "rectificaciones": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true
      }
    },
    "ivaDevengado": {
      "type": [
        "number",
        "null"
      ],
      "description": "Modelo 303: total IVA devengado (box 27)"
    },
    "ivaDeducible": {
      "type": [
        "number",
        "null"
      ],
      "description": "Modelo 303: total IVA deducible (box 45)"
    },
    "ivaResultado": {
      "type": [
        "number",
        "null"
      ],
      "description": "Modelo 303: result (box 71)"
    },
    "source_file": {
      "type": [
        "string",
        "null"
      ]
    }
  }
}