{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/astranexo-com/json-schema/astranexo-com-document-schema.json",
  "title": "Document",
  "x-generated": "2026-11-01",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/aster-openapi.yaml#/components/schemas/Document",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer",
      "format": "int64"
    },
    "transaction_id": {
      "type": "string"
    },
    "document_key": {
      "type": [
        "string",
        "null"
      ]
    },
    "consecutive_number": {
      "type": [
        "string",
        "null"
      ]
    },
    "document_type": {
      "type": "string"
    },
    "document_type_name": {
      "type": [
        "string",
        "null"
      ]
    },
    "status": {
      "$ref": "#/$defs/DocumentStatus"
    },
    "environment": {
      "$ref": "#/$defs/Environment"
    },
    "emisor_identification": {
      "type": [
        "string",
        "null"
      ]
    },
    "emisor_name": {
      "type": [
        "string",
        "null"
      ]
    },
    "receptor_identification": {
      "type": [
        "string",
        "null"
      ]
    },
    "receptor_name": {
      "type": [
        "string",
        "null"
      ]
    },
    "total_amount": {
      "type": "number"
    },
    "tax_amount": {
      "type": "number"
    },
    "net_amount": {
      "type": "number"
    },
    "currency": {
      "type": "string"
    },
    "exchange_rate": {
      "type": [
        "number",
        "null"
      ]
    },
    "hacienda_status": {
      "type": [
        "string",
        "null"
      ]
    },
    "hacienda_message": {
      "type": [
        "string",
        "null"
      ]
    },
    "hacienda_response_at": {
      "type": "string",
      "format": "date-time"
    },
    "xml_path": {
      "type": [
        "string",
        "null"
      ]
    },
    "pdf_path": {
      "type": [
        "string",
        "null"
      ]
    },
    "processing_time_ms": {
      "type": [
        "integer",
        "null"
      ]
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "type": "string",
      "format": "date-time"
    },
    "signed_xml": {
      "type": "string",
      "description": "XML firmado."
    },
    "response_xml": {
      "type": "string",
      "description": "XML de respuesta de Hacienda, si ya existe."
    },
    "rejections": {
      "type": "array",
      "description": "Errores y advertencias de Hacienda, si los hay.",
      "items": {
        "$ref": "#/$defs/Rejection"
      }
    }
  },
  "$defs": {
    "DocumentStatus": {
      "type": "string",
      "description": "Estado del documento en Aster: `processing` (firmado, enviándose), `sent`, `queued` (Hacienda no disponible; se reintenta), `accepted`, `rejected`, `error` (nunca llegó a Hacienda).",
      "enum": [
        "processing",
        "sent",
        "queued",
        "accepted",
        "rejected",
        "error"
      ]
    },
    "Environment": {
      "type": "string",
      "enum": [
        "staging",
        "production"
      ],
      "description": "Ambiente de Hacienda. Con claves de Aster lo decide la clave."
    },
    "Rejection": {
      "type": "object",
      "properties": {
        "error_code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "friendly_message": {
          "type": "string"
        },
        "element_name": {
          "type": "string"
        },
        "location": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "row": {
          "type": "integer"
        },
        "col": {
          "type": "integer"
        }
      }
    }
  }
}