{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/frihet-io/json-schema/frihet-io-deposit-schema.json",
  "title": "Deposit",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/frihet-io-deposits-api-openapi.yml#/components/schemas/Deposit",
  "allOf": [
    {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "Unique identifier"
        },
        "createdAt": {
          "type": "string",
          "format": "date-time"
        },
        "updatedAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    {
      "$ref": "#/$defs/DepositCreate"
    },
    {
      "type": "object",
      "properties": {
        "status": {
          "$ref": "#/$defs/DepositStatus"
        },
        "appliedAmount": {
          "type": "number",
          "description": "Total amount already applied to invoices"
        },
        "remainingBalance": {
          "type": "number",
          "description": "Remaining balance available for application or refund"
        },
        "refundedAmount": {
          "type": "number",
          "description": "Total amount refunded to the client"
        },
        "applications": {
          "type": "array",
          "description": "List of invoice applications for this deposit",
          "items": {
            "type": "object",
            "properties": {
              "invoiceId": {
                "type": "string"
              },
              "invoiceNumber": {
                "type": "string"
              },
              "amount": {
                "type": "number"
              },
              "appliedAt": {
                "type": "string",
                "format": "date"
              }
            }
          }
        }
      }
    }
  ],
  "$defs": {
    "DepositCreate": {
      "type": "object",
      "required": [
        "clientId",
        "clientName",
        "amount",
        "description",
        "receivedDate"
      ],
      "properties": {
        "clientId": {
          "type": "string",
          "description": "ID of the client who made the deposit"
        },
        "clientName": {
          "type": "string",
          "description": "Client name (denormalized for display)"
        },
        "amount": {
          "type": "number",
          "description": "Deposit amount (must be positive)"
        },
        "currency": {
          "type": "string",
          "description": "Currency code (ISO 4217)",
          "default": "EUR"
        },
        "description": {
          "type": "string",
          "description": "Description of the deposit"
        },
        "receivedDate": {
          "type": "string",
          "format": "date",
          "description": "Date the deposit was received (YYYY-MM-DD)"
        },
        "paymentMethod": {
          "type": "string",
          "description": "Payment method used"
        },
        "paymentReference": {
          "type": "string",
          "description": "Payment reference or transaction ID"
        }
      }
    },
    "DepositStatus": {
      "type": "string",
      "enum": [
        "active",
        "partially_applied",
        "fully_applied",
        "refunded"
      ]
    }
  }
}