{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/luckpanda-app/json-schema/luckpanda-app-invoice-result-schema.json",
  "title": "InvoiceResult",
  "x-generated": "2026-10-28",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/luckpanda-app-openapi.yaml#/components/schemas/InvoiceResult",
  "type": "object",
  "required": [
    "steps"
  ],
  "properties": {
    "document": {
      "$ref": "#/$defs/Document"
    },
    "document_id": {
      "$ref": "#/$defs/Uuid"
    },
    "external_ref": {
      "type": [
        "string",
        "null"
      ]
    },
    "view_url": {
      "type": [
        "string",
        "null"
      ],
      "description": "Absolute link to the client page of the invoice. Null until the document has a public link."
    },
    "pdf_url": {
      "type": [
        "string",
        "null"
      ],
      "description": "Absolute link to the invoice PDF (view_url + /pdf, no sign-in). The signed-in PDF is GET /documents/{documentId}/pdf."
    },
    "created": {
      "type": "boolean",
      "description": "false when the external_ref was already used"
    },
    "correlation_id": {
      "$ref": "#/$defs/Uuid"
    },
    "steps": {
      "type": "object",
      "required": [
        "create",
        "issue",
        "payment",
        "send"
      ],
      "properties": {
        "create": {
          "$ref": "#/$defs/StepStatus"
        },
        "issue": {
          "$ref": "#/$defs/StepStatus"
        },
        "payment": {
          "allOf": [
            {
              "$ref": "#/$defs/StepStatus"
            },
            {
              "type": "object",
              "properties": {
                "receipt_id": {
                  "$ref": "#/$defs/Uuid"
                }
              }
            }
          ]
        },
        "send": {
          "allOf": [
            {
              "$ref": "#/$defs/StepStatus"
            },
            {
              "type": "object",
              "properties": {
                "delivery_id": {
                  "$ref": "#/$defs/Uuid"
                },
                "recipient": {
                  "type": "string"
                },
                "state": {
                  "type": "string",
                  "enum": [
                    "queued",
                    "sending",
                    "sent",
                    "link_only",
                    "failed"
                  ]
                },
                "cc": {
                  "type": "array",
                  "description": "One entry per copy with its own status and delivery"
                }
              }
            }
          ]
        }
      }
    }
  },
  "$defs": {
    "CommandResult": {
      "type": "object",
      "required": [
        "operation_id",
        "status",
        "correlation_id"
      ],
      "properties": {
        "operation_id": {
          "$ref": "#/$defs/Uuid"
        },
        "status": {
          "type": "string",
          "enum": [
            "succeeded",
            "awaiting_approval",
            "preview"
          ]
        },
        "correlation_id": {
          "$ref": "#/$defs/Uuid"
        },
        "resource": {
          "type": "object",
          "additionalProperties": true
        },
        "approval_request_id": {
          "$ref": "#/$defs/Uuid"
        }
      }
    },
    "Currency": {
      "type": "string",
      "pattern": "^[A-Z]{3}$"
    },
    "Document": {
      "type": "object",
      "description": "The document view (abridged).",
      "required": [
        "id",
        "kind",
        "lifecycle",
        "version"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/Uuid"
        },
        "kind": {
          "type": "string"
        },
        "lifecycle": {
          "type": "string",
          "enum": [
            "draft",
            "issued",
            "cancelled"
          ]
        },
        "settlement": {
          "type": "string",
          "enum": [
            "unpaid",
            "part_paid",
            "paid",
            "overpaid",
            "not_applicable"
          ]
        },
        "version": {
          "type": "integer"
        },
        "currency": {
          "$ref": "#/$defs/Currency"
        },
        "payable_minor": {
          "type": "integer"
        },
        "paid_minor": {
          "type": "integer"
        },
        "external_ref": {
          "type": [
            "string",
            "null"
          ]
        },
        "doc": {
          "type": "object",
          "description": "The editor document: number, dates, parties, lines, totals",
          "additionalProperties": true
        },
        "operation": {
          "$ref": "#/$defs/CommandResult"
        }
      },
      "additionalProperties": true
    },
    "StepStatus": {
      "type": "object",
      "required": [
        "status"
      ],
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "succeeded",
            "already_done",
            "skipped",
            "not_requested",
            "awaiting_approval",
            "failed"
          ]
        },
        "operation_id": {
          "$ref": "#/$defs/Uuid"
        },
        "error": {
          "type": "object",
          "properties": {
            "code": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "status": {
              "type": "integer"
            },
            "field_errors": {}
          }
        }
      },
      "additionalProperties": true
    },
    "Uuid": {
      "type": "string",
      "format": "uuid"
    }
  }
}