openapi: 3.0.3
info:
  title: axiomaQ API (Veri*Factu)
  description: API B2B para emisión, firma y envío de facturas electrónicas a la AEAT bajo el marco normativo VERI*FACTU (RD 1007/2023).
  version: "1.0.0"
servers:
  - url: https://axiomaq-api.vercel.app
    description: Servidor principal axiomaQ API
security:
  - bearerAuth: []
paths:
  /api/v1/invoices:
    post:
      summary: Emitir factura en Producción (AEAT)
      description: Genera la huella criptográfica, firma en XAdES y envía la factura de forma real a la Agencia Tributaria.
      operationId: createProductionInvoice
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/InvoiceRequest'
      responses:
        '200':
          description: Factura aceptada y registrada por la AEAT.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InvoiceResponse'
        '400':
          description: Error de validación del payload o de negocio fiscal.
        '401':
          description: No autorizado. Bearer Token inválido.
  /api/v1/sandbox/invoices:
    post:
      summary: Emitir factura en Sandbox (Pruebas)
      description: Simula la validación matemática y estructural del XML sin impactar tu certificado real ni notificar a la AEAT.
      operationId: createSandboxInvoice
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/InvoiceRequest'
      responses:
        '200':
          description: Factura validada correctamente por el entorno Sandbox.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InvoiceResponse'
        '400':
          description: Error de validación del payload.
        '401':
          description: No autorizado. Bearer Token inválido.
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
  schemas:
    InvoiceRequest:
      type: object
      required:
        - serie
        - fecha_emision
        - conceptos
      properties:
        tipo_factura:
          type: string
          enum: [F1, F2, F3, R1, R2, R3, R4, R5]
          default: F1
          description: F1=Completa, F2=Ticket, Rx=Rectificativas.
        serie:
          type: string
          example: "2026"
        fecha_emision:
          type: string
          format: date
          example: "2026-07-30"
        external_id:
          type: string
          description: ID interno del ERP del cliente.
        cliente:
          type: object
          properties:
            nif:
              type: string
            nombre:
              type: string
        factura_rectificada:
          type: object
          properties:
            numero:
              type: string
            fecha_emision:
              type: string
        conceptos:
          type: array
          items:
            type: object
            required:
              - importe
              - iva
            properties:
              descripcion:
                type: string
              importe:
                type: number
                format: float
              iva:
                type: integer
                enum: [0, 4, 10, 21]
    InvoiceResponse:
      type: object
      properties:
        success:
          type: boolean
        data:
          type: object
          properties:
            invoice_number:
              type: string
            sif:
              type: object
              properties:
                status:
                  type: string
                  example: "aceptado"
                csv:
                  type: string
                  example: "A-78LVS89DA8UFV3"
                qr_url:
                  type: string