{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/facture-ar/json-schema/facture-ar-template-input-schema.json",
  "title": "TemplateInput",
  "x-generated": "2026-11-07",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/facture-ar-openapi.json#/components/schemas/TemplateInput",
  "type": "object",
  "required": [
    "name"
  ],
  "properties": {
    "name": {
      "type": "string",
      "maxLength": 120
    },
    "cuitId": {
      "type": [
        "string",
        "null"
      ],
      "description": "CUIT emisor. Obligatorio en modo automático y en las recurrentes"
    },
    "ptoVta": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 1,
      "maximum": 99999
    },
    "mode": {
      "type": "string",
      "enum": [
        "manual",
        "automatic"
      ],
      "default": "manual"
    },
    "concepto": {
      "type": "integer",
      "enum": [
        1,
        2,
        3
      ],
      "default": 1
    },
    "ivaRate": {
      "type": "number",
      "enum": [
        0,
        2.5,
        5,
        10.5,
        21,
        27
      ],
      "default": 21
    },
    "pricesIncludeIva": {
      "type": "boolean",
      "default": true
    },
    "receiverDocType": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "CUIT",
        "CUIL",
        "DNI",
        null
      ],
      "description": "Cliente fijo: todas las facturas de la plantilla van a él"
    },
    "receiverDocNumber": {
      "type": [
        "string",
        "null"
      ],
      "maxLength": 20
    },
    "receiverName": {
      "type": [
        "string",
        "null"
      ],
      "maxLength": 200
    },
    "receiverCondicionIva": {
      "type": [
        "integer",
        "null"
      ]
    },
    "receiverEmail": {
      "type": [
        "string",
        "null"
      ],
      "format": "email"
    },
    "items": {
      "type": [
        "array",
        "null"
      ],
      "maxItems": 100,
      "description": "Líneas fijas, para las facturas recurrentes",
      "items": {
        "type": "object",
        "required": [
          "description",
          "quantity",
          "unitPrice"
        ],
        "properties": {
          "description": {
            "type": "string"
          },
          "quantity": {
            "type": "number"
          },
          "unitPrice": {
            "type": "number",
            "minimum": 0
          }
        }
      }
    },
    "priceList": {
      "type": [
        "array",
        "null"
      ],
      "maxItems": 2000,
      "description": "Precios para documentos que no los traen (remitos)",
      "items": {
        "type": "object",
        "required": [
          "description",
          "unitPrice"
        ],
        "properties": {
          "description": {
            "type": "string"
          },
          "unitPrice": {
            "type": "number",
            "minimum": 0
          }
        }
      }
    },
    "instructions": {
      "type": [
        "string",
        "null"
      ],
      "maxLength": 4000,
      "description": "Lo que la IA tiene que saber para leer este tipo de documento"
    },
    "columnMapping": {
      "type": [
        "object",
        "null"
      ],
      "description": "Columnas de la planilla → campos de la factura",
      "properties": {
        "headerRow": {
          "type": "integer",
          "minimum": 1
        },
        "columns": {
          "type": "object",
          "description": "Campo → nombre de la columna. Campos: receiverName, receiverDoc, receiverEmail, receiverCondicionIva, receiverAddress, description, quantity, unitPrice, lineTotal, ivaRate, reference, date, concepto",
          "additionalProperties": {
            "type": "string"
          }
        },
        "groupBy": {
          "type": [
            "string",
            "null"
          ]
        },
        "pricesIncludeIva": {
          "type": "boolean"
        }
      }
    },
    "paymentTermDays": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 0,
      "maximum": 365
    },
    "sendEmail": {
      "type": "boolean",
      "default": true,
      "description": "Mandarle la factura al cliente por email"
    },
    "emailCopyTo": {
      "type": [
        "string",
        "null"
      ],
      "format": "email"
    },
    "recurrence": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "monthly",
        null
      ],
      "description": "monthly: emite las líneas fijas todos los meses en dayOfMonth"
    },
    "dayOfMonth": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 1,
      "maximum": 28
    },
    "active": {
      "type": "boolean",
      "default": true
    }
  }
}