{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:coos:schema:Levy",
  "title": "Levy",
  "description": "An amount owners are required to pay: regular strata fees under a budget, or a special levy approved by the owners.",
  "type": "object",
  "x-domain": "financial",
  "x-status": "experimental",
  "x-since": "0.1.0-draft",
  "x-relationships": [
    {
      "field": "strataCorporationId",
      "target": "StrataCorporation",
      "cardinality": "one",
      "required": true
    },
    {
      "field": "budgetId",
      "target": "Budget",
      "cardinality": "one",
      "required": false
    },
    {
      "field": "approvedByResolutionId",
      "target": "Resolution",
      "cardinality": "one",
      "required": false
    }
  ],
  "x-validationRules": [
    "The sum of allocations[].amount should equal totalAmount, allowing for rounding.",
    "approvedByResolutionId is expected when levyType is specialLevy."
  ],
  "x-legalReviewNotes": [
    "Confirm treatment of instalments, interest and refunds of unused special levy money."
  ],
  "required": [
    "id",
    "strataCorporationId",
    "levyType",
    "totalAmount"
  ],
  "additionalProperties": false,
  "properties": {
    "id": {
      "$ref": "urn:coos:schema:common#/$defs/Identifier",
      "description": "Stable identifier of this Levy record."
    },
    "strataCorporationId": {
      "$ref": "urn:coos:schema:common#/$defs/Identifier",
      "description": "The strata corporation this record belongs to.",
      "x-references": "StrataCorporation"
    },
    "levyType": {
      "type": "string",
      "description": "Kind of levy.",
      "enum": [
        "strataFee",
        "specialLevy"
      ],
      "x-enumDescriptions": {
        "strataFee": "Regular strata fees (monthly contributions) under the budget.",
        "specialLevy": "Special levy approved by the owners."
      }
    },
    "purpose": {
      "type": "string",
      "description": "Purpose of the levy.",
      "maxLength": 1000
    },
    "totalAmount": {
      "$ref": "urn:coos:schema:common#/$defs/Money",
      "description": "Total amount to be raised."
    },
    "allocationBasis": {
      "type": "string",
      "description": "How the total is shared between strata lots.",
      "enum": [
        "unitEntitlement",
        "other"
      ],
      "x-enumDescriptions": {
        "unitEntitlement": "In proportion to unit entitlement.",
        "other": "Another basis approved by the owners."
      }
    },
    "budgetId": {
      "$ref": "urn:coos:schema:common#/$defs/Identifier",
      "description": "Budget the strata fees are based on, when levyType is strataFee.",
      "x-references": "Budget"
    },
    "approvedByResolutionId": {
      "$ref": "urn:coos:schema:common#/$defs/Identifier",
      "description": "Resolution approving the levy.",
      "x-references": "Resolution"
    },
    "dueDate": {
      "$ref": "urn:coos:schema:common#/$defs/Date",
      "description": "Date payment is due, or the first due date when paid in instalments."
    },
    "allocations": {
      "type": "array",
      "description": "Amount payable by each strata lot.",
      "items": {
        "type": "object",
        "required": [
          "strataLotId",
          "amount"
        ],
        "additionalProperties": false,
        "properties": {
          "strataLotId": {
            "$ref": "urn:coos:schema:common#/$defs/Identifier",
            "description": "Strata lot.",
            "x-references": "StrataLot"
          },
          "amount": {
            "$ref": "urn:coos:schema:common#/$defs/Money",
            "description": "Amount payable by this strata lot."
          }
        }
      }
    },
    "extensions": {
      "$ref": "urn:coos:schema:common#/$defs/Extensions",
      "description": "Implementation-specific data, namespaced by reverse domain."
    }
  }
}
