{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/facture-ar/json-schema/facture-ar-draft-schema.json",
  "title": "Draft",
  "description": "Un borrador de factura armado desde un documento, una planilla, datos enviados por API o una plantilla recurrente",
  "x-generated": "2026-11-07",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/facture-ar-openapi.json#/components/schemas/Draft",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "status": {
      "type": "string",
      "enum": [
        "extracting",
        "review",
        "queued",
        "invoiced",
        "error",
        "discarded"
      ],
      "description": "extracting: leyéndose; review: espera revisión; queued: enviado a ARCA; invoiced: facturado; error: no se pudo leer o emitir; discarded: descartado"
    },
    "mode": {
      "type": "string",
      "enum": [
        "manual",
        "automatic"
      ],
      "description": "automatic: se emite solo si no hay observaciones"
    },
    "source": {
      "type": "string",
      "enum": [
        "upload",
        "google_drive",
        "zapier",
        "api",
        "recurring",
        "mcp",
        "whatsapp"
      ]
    },
    "sourceRef": {
      "type": [
        "string",
        "null"
      ]
    },
    "fileName": {
      "type": [
        "string",
        "null"
      ]
    },
    "mimeType": {
      "type": [
        "string",
        "null"
      ]
    },
    "hasFile": {
      "type": "boolean"
    },
    "templateId": {
      "type": [
        "string",
        "null"
      ]
    },
    "templateName": {
      "type": [
        "string",
        "null"
      ]
    },
    "cuitId": {
      "type": [
        "string",
        "null"
      ]
    },
    "ptoVta": {
      "type": [
        "integer",
        "null"
      ]
    },
    "environment": {
      "type": "string",
      "enum": [
        "production",
        "homologation"
      ]
    },
    "data": {
      "oneOf": [
        {
          "$ref": "#/$defs/DraftData"
        },
        {
          "type": "null"
        }
      ]
    },
    "total": {
      "type": [
        "number",
        "null"
      ],
      "description": "Total calculado con las líneas; null si falta algún precio"
    },
    "voucherLetter": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "A",
        "B",
        "C",
        null
      ]
    },
    "confidence": {
      "type": [
        "number",
        "null"
      ],
      "description": "Confianza de la lectura con IA, de 0 a 1"
    },
    "issues": {
      "type": "array",
      "description": "Observaciones que hay que revisar",
      "items": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "enum": [
              "no_cuit",
              "no_lines",
              "missing_price",
              "invalid_amount",
              "total_mismatch",
              "invalid_document",
              "unidentified_receiver",
              "foreign_currency",
              "low_confidence",
              "possible_duplicate",
              "ai_note",
              "ai_info"
            ]
          },
          "message": {
            "type": "string"
          }
        }
      }
    },
    "errorMessage": {
      "type": [
        "string",
        "null"
      ]
    },
    "invoice": {
      "type": [
        "object",
        "null"
      ],
      "description": "La factura emitida desde el borrador",
      "properties": {
        "id": {
          "type": "string"
        },
        "voucherNumber": {
          "type": "integer"
        },
        "ptoVta": {
          "type": [
            "integer",
            "null"
          ]
        },
        "invoiceType": {
          "type": [
            "integer",
            "null"
          ]
        },
        "status": {
          "type": "string"
        },
        "amount": {
          "type": "number"
        }
      }
    },
    "emailStatus": {
      "type": [
        "string",
        "null"
      ],
      "description": "Estado del envío de la factura por email"
    },
    "url": {
      "type": "string",
      "description": "Link al borrador en el dashboard"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time"
    }
  },
  "$defs": {
    "DraftData": {
      "type": "object",
      "description": "Los datos de la factura propuesta",
      "required": [
        "lines"
      ],
      "properties": {
        "receiver": {
          "type": "object",
          "properties": {
            "name": {
              "type": [
                "string",
                "null"
              ],
              "maxLength": 200
            },
            "docType": {
              "type": [
                "string",
                "null"
              ],
              "description": "CUIT, CUIL o DNI; null = consumidor final sin identificar"
            },
            "docNumber": {
              "type": [
                "string",
                "null"
              ],
              "description": "CUIT, CUIL o DNI, con o sin guiones"
            },
            "condicionIva": {
              "type": [
                "integer",
                "null"
              ],
              "description": "Condición frente al IVA del receptor (código de ARCA). Si falta, se busca en el padrón"
            },
            "email": {
              "type": [
                "string",
                "null"
              ],
              "format": "email",
              "description": "Si está, se le manda la factura"
            },
            "address": {
              "type": [
                "string",
                "null"
              ],
              "maxLength": 300
            }
          }
        },
        "concepto": {
          "type": "integer",
          "enum": [
            1,
            2,
            3
          ],
          "default": 1,
          "description": "1 productos, 2 servicios, 3 productos y servicios"
        },
        "serviceFrom": {
          "type": [
            "string",
            "null"
          ],
          "format": "date",
          "description": "AAAA-MM-DD, servicios"
        },
        "serviceTo": {
          "type": [
            "string",
            "null"
          ],
          "format": "date",
          "description": "AAAA-MM-DD, servicios"
        },
        "paymentDue": {
          "type": [
            "string",
            "null"
          ],
          "format": "date",
          "description": "Vencimiento del pago, AAAA-MM-DD"
        },
        "pricesIncludeIva": {
          "type": "boolean",
          "default": true,
          "description": "Los precios de las líneas incluyen IVA"
        },
        "lines": {
          "type": "array",
          "maxItems": 200,
          "items": {
            "type": "object",
            "required": [
              "description",
              "unitPrice"
            ],
            "properties": {
              "description": {
                "type": "string",
                "maxLength": 200
              },
              "quantity": {
                "type": "number",
                "exclusiveMinimum": 0,
                "default": 1
              },
              "unitPrice": {
                "type": [
                  "number",
                  "null"
                ],
                "minimum": 0,
                "description": "null si el documento no trae precio"
              },
              "ivaRate": {
                "type": "number",
                "enum": [
                  0,
                  2.5,
                  5,
                  10.5,
                  21,
                  27
                ],
                "default": 21,
                "description": "Alícuota de IVA en porcentaje"
              }
            }
          }
        },
        "documentTotal": {
          "type": [
            "number",
            "null"
          ],
          "description": "Total impreso en el documento, para controlar las líneas"
        },
        "currency": {
          "type": "string",
          "minLength": 3,
          "maxLength": 3,
          "default": "ARS",
          "description": "Moneda ISO 4217"
        },
        "documentDate": {
          "type": [
            "string",
            "null"
          ],
          "format": "date",
          "description": "Fecha del documento, AAAA-MM-DD. La factura se emite con la fecha del día"
        },
        "reference": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 100,
          "description": "Número de remito, pedido o referencia"
        },
        "description": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 500,
          "description": "Texto libre que va en la factura"
        }
      }
    }
  }
}