{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/timbrix-mx/json-schema/timbrix-mx-create-invoice-dto-schema.json",
  "title": "CreateInvoiceDto",
  "x-generated": "2026-11-26",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/timbrix-mx-openapi.yaml#/components/schemas/CreateInvoiceDto",
  "type": "object",
  "properties": {
    "type": {
      "type": "string",
      "enum": [
        "I",
        "E",
        "T"
      ],
      "description": "Ingreso, Egreso, or Traslado (default: I)"
    },
    "relatedInvoiceUuid": {
      "type": "string",
      "description": "Required when `type` is `E` (Egreso/nota de crédito) — UUID fiscal of the original Ingreso CFDI it credits. Must belong to this organization and be a vigente Ingreso."
    },
    "relatedCfdis": {
      "description": "CFDI relacionados. Fase actual: un solo elemento `{ type: \"04\", uuids: [<uuid del CFDI que se sustituye>] }`, solo para Ingreso y Traslado. Para Egreso usa `relatedInvoiceUuid`.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/RelatedCfdiDto"
      }
    },
    "series": {
      "type": "string",
      "description": "Opcional: si no se manda se usa la serie predeterminada del tipo (I y T: A, E: NC, salvo que la organización la cambie). De 1 a 25 caracteres, sin |.",
      "maxLength": 25
    },
    "folioNumber": {
      "type": "string",
      "description": "Opcional: si no se manda se usa el siguiente folio de la serie. Un folio que ya existe en la serie se rechaza con 409 FOLIO_ALREADY_USED. De 1 a 40 caracteres, sin |.",
      "maxLength": 40
    },
    "date": {
      "type": "string"
    },
    "paymentForm": {
      "type": "string",
      "description": "SAT forma de pago catalog code — required unless `type` is `T` (Traslado)"
    },
    "paymentMethod": {
      "type": "string",
      "enum": [
        "PUE",
        "PPD"
      ],
      "description": "Default: PUE"
    },
    "currency": {
      "type": "string",
      "description": "Default: MXN"
    },
    "exchange": {
      "type": "number",
      "description": "Default: 1"
    },
    "export": {
      "type": "string",
      "description": "SAT clave de exportación catalog code — default: 01"
    },
    "paymentConditions": {
      "type": "string",
      "maxLength": 1000,
      "description": "Condiciones de pago (CondicionesDePago del CFDI). Solo para Ingreso y Egreso; de 1 a 1000 caracteres, sin \"|\"."
    },
    "use": {
      "type": "string",
      "description": "SAT uso CFDI catalog code"
    },
    "customer": {
      "$ref": "#/$defs/InvoiceCustomerDto"
    },
    "customerId": {
      "type": "string",
      "description": "Existing customer ID — mutually exclusive with `customer`"
    },
    "items": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/InvoiceItemDto"
      }
    },
    "idempotencyKey": {
      "type": "string",
      "description": "Client-supplied key to safely retry this request without double-stamping. If an invoice was already created for this organization with the same key, that invoice is returned instead of stamping again."
    }
  },
  "required": [
    "date",
    "use",
    "items"
  ],
  "$defs": {
    "InvoiceCustomerDto": {
      "type": "object",
      "properties": {
        "legalName": {
          "type": "string"
        },
        "taxId": {
          "type": "string"
        },
        "taxSystem": {
          "type": "string",
          "description": "SAT régimen fiscal code — required unless the customer is público en general"
        },
        "zip": {
          "type": "string"
        }
      },
      "required": [
        "legalName",
        "taxId"
      ]
    },
    "InvoiceItemDto": {
      "type": "object",
      "properties": {
        "quantity": {
          "type": "number"
        },
        "productId": {
          "type": "string",
          "description": "Existing product/service ID — mutually exclusive with `productKey`/`unitKey`/`description`/`unitPrice` (inline concept data)"
        },
        "description": {
          "type": "string",
          "description": "Required unless `productId` is provided"
        },
        "unitPrice": {
          "type": "number",
          "description": "Required unless `productId` is provided"
        },
        "amount": {
          "type": "number",
          "description": "Line total (`quantity * unitPrice`). Required unless `productId` is provided — with `productId` it is computed from the product and, if sent, must match the computed value within $0.01"
        },
        "productKey": {
          "type": "string",
          "description": "Required unless `productId` is provided"
        },
        "unitKey": {
          "type": "string",
          "description": "Required unless `productId` is provided"
        },
        "unit": {
          "type": "string"
        },
        "taxObject": {
          "type": "string"
        },
        "taxes": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/InvoiceTaxDto"
          }
        },
        "discount": {
          "type": "number",
          "minimum": 0,
          "description": "Descuento del concepto en la moneda de la factura. La base de los impuestos es importe − descuento."
        }
      },
      "required": [
        "quantity"
      ]
    },
    "InvoiceTaxDto": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "description": "Clave c_Impuesto del SAT: \"001\" ISR (solo retención), \"002\" IVA o \"003\" IEPS. También acepta los nombres; cualquier otro valor se rechaza."
        },
        "factorType": {
          "type": "string"
        },
        "rate": {
          "type": "string"
        },
        "base": {
          "type": "number"
        },
        "amount": {
          "type": "number"
        },
        "withholding": {
          "type": "boolean",
          "description": "true = retención (Impuestos.Retenciones), false/omitted = traslado (Impuestos.Traslados)"
        }
      },
      "required": [
        "type",
        "factorType"
      ]
    },
    "RelatedCfdiDto": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "01",
            "02",
            "03",
            "04",
            "05",
            "06",
            "07"
          ],
          "description": "Clave SAT c_TipoRelacion. Por ahora solo se admite 04 (sustitución de los CFDI previos)."
        },
        "uuids": {
          "description": "UUID fiscal de los CFDI relacionados",
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "type",
        "uuids"
      ]
    }
  }
}