{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://vetdatastandards.com/schemas/v0.1/invoice.schema.json",
  "title": "Invoice",
  "type": "object",
  "additionalProperties": false,
  "required": ["id", "practiceId", "clientId", "currency", "status", "source"],
  "properties": {
    "id": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/id" },
    "source": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/source" },
    "matchKeys": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/matchKeys" },
    "createdAt": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/dateTime" },
    "updatedAt": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/dateTime" },
    "deletedAt": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/dateTime" },
    "active": { "type": "boolean" },
    "extensions": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/extensions" },
    "practiceId": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/id" },
    "clientId": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/id" },
    "patientId": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/id" },
    "appointmentId": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/id" },
    "consultationId": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/id" },
    "locationId": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/id" },
    "currency": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/currency" },
    "currencyRaw": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/rawText" },
    "status": {
      "type": "string",
      "enum": ["draft", "issued", "partially_paid", "paid", "void", "other"]
    },
    "statusRaw": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/rawText" },
    "kind": {
      "type": "string",
      "enum": ["invoice", "estimate", "credit_note", "other"]
    },
    "kindRaw": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/rawText" },
    "documentNumber": { "type": "string", "minLength": 1, "maxLength": 64 },
    "issuedAt": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/dateTime" },
    "dueDate": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/date" },
    "subtotal": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/decimal" },
    "taxTotal": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/decimal" },
    "total": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/decimal" },
    "amountPaid": { "$ref": "https://vetdatastandards.com/schemas/v0.1/common.schema.json#/$defs/decimal" }
  },
  "allOf": [
    {
      "if": {
        "properties": { "status": { "const": "other" } },
        "required": ["status"]
      },
      "then": { "required": ["statusRaw"] }
    },
    {
      "if": {
        "properties": { "kind": { "const": "other" } },
        "required": ["kind"]
      },
      "then": { "required": ["kindRaw"] }
    }
  ]
}
