{
  "$defs": {
    "AccrualKind": {
      "description": "Direction of the accrual.",
      "oneOf": [
        {
          "const": "accrued_expense",
          "description": "Expense incurred but not yet paid (utilities, payroll accrual).",
          "type": "string"
        },
        {
          "const": "deferred_revenue",
          "description": "Revenue received but not yet earned (SaaS prepaid term, annual\nsubscription). IFRS 15 §B47 deferred revenue.",
          "type": "string"
        },
        {
          "const": "prepaid_expense",
          "description": "Expense paid but not yet incurred (annual insurance, prepaid\nrent). IAS 1 matching principle.",
          "type": "string"
        },
        {
          "const": "accrued_revenue",
          "description": "Revenue earned but not yet billed (over-time contract revenue).",
          "type": "string"
        }
      ]
    },
    "AccrualStatus": {
      "description": "Lifecycle status.",
      "enum": [
        "active",
        "released",
        "reversed",
        "partially_released"
      ],
      "type": "string"
    },
    "IsoCurrency": {
      "description": "ISO 4217 currency code.",
      "pattern": "^[A-Z]{3}$",
      "type": "string"
    },
    "IsoDate": {
      "description": "ISO 8601 date (YYYY-MM-DD).",
      "format": "date",
      "type": "string"
    },
    "MonetaryAmount": {
      "description": "A monetary value with currency.",
      "properties": {
        "amount": {
          "format": "double",
          "type": "number"
        },
        "currency": {
          "$ref": "#/$defs/IsoCurrency"
        }
      },
      "required": [
        "amount",
        "currency"
      ],
      "type": "object"
    },
    "PathRef": {
      "description": "Path-based cross-reference relative to .corpospec/ root.\nPattern: `^[a-z0-9_-]+(/[a-z0-9_.-]+)+$`",
      "pattern": "^[a-z0-9_-]+(/[a-z0-9_.-]+)+$",
      "type": "string"
    },
    "RecognitionPattern": {
      "description": "How the accrual releases over its life.",
      "oneOf": [
        {
          "const": "straight_line",
          "description": "Equal recognition per period across the life.",
          "type": "string"
        },
        {
          "const": "usage_based",
          "description": "Recognition tracks usage (consumption-based SaaS).",
          "type": "string"
        },
        {
          "const": "milestone",
          "description": "Recognition triggered by named milestones.",
          "type": "string"
        },
        {
          "const": "percent_complete",
          "description": "Recognition tracks percent-complete (long-term projects).",
          "type": "string"
        }
      ]
    },
    "ReleasePeriod": {
      "description": "One period's release.",
      "properties": {
        "amount": {
          "description": "Amount released this period.",
          "format": "double",
          "type": "number"
        },
        "gl_entry": {
          "anyOf": [
            {
              "$ref": "#/$defs/PathRef"
            },
            {
              "type": "null"
            }
          ],
          "description": "PathRef into the JournalEntry that released this period's amount,\nwhen posted."
        },
        "period": {
          "$ref": "#/$defs/PathRef",
          "description": "PathRef into AccountingPeriod for this release."
        }
      },
      "required": [
        "period",
        "amount"
      ],
      "type": "object"
    }
  },
  "$id": "https://corpospec.com/schemas/v0.16.0/accrual-schedule.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "Accrual-schedule record.",
  "properties": {
    "counterparty": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "Optional counterparty (customer for deferred revenue, vendor for\nprepaid)."
    },
    "current_balance": {
      "description": "Current outstanding balance (total_amount minus releases so far).\nRecomputed on read; persisted for audit.",
      "format": "double",
      "type": "number"
    },
    "end": {
      "$ref": "#/$defs/IsoDate",
      "description": "Recognition window end."
    },
    "entity": {
      "$ref": "#/$defs/PathRef",
      "description": "Subject entity."
    },
    "id": {
      "$ref": "#/$defs/PathRef",
      "description": "PathRef identifier, conventionally `financials/accruals/<slug>`."
    },
    "kind": {
      "$ref": "#/$defs/AccrualKind",
      "description": "Direction (deferred revenue / prepaid expense / accrued)."
    },
    "note": {
      "description": "Free-form note.",
      "type": [
        "string",
        "null"
      ]
    },
    "recognition_pattern": {
      "$ref": "#/$defs/RecognitionPattern",
      "description": "Recognition pattern."
    },
    "release_periods": {
      "description": "Per-period release schedule.",
      "items": {
        "$ref": "#/$defs/ReleasePeriod"
      },
      "type": "array"
    },
    "source_document": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "Source document (invoice, contract)."
    },
    "start": {
      "$ref": "#/$defs/IsoDate",
      "description": "Recognition window start."
    },
    "status": {
      "$ref": "#/$defs/AccrualStatus",
      "description": "Status."
    },
    "total_amount": {
      "$ref": "#/$defs/MonetaryAmount",
      "description": "Total amount to recognise over the life."
    }
  },
  "required": [
    "id",
    "entity",
    "kind",
    "total_amount",
    "recognition_pattern",
    "start",
    "end",
    "release_periods",
    "current_balance",
    "status"
  ],
  "title": "AccrualSchedule",
  "type": "object",
  "x-corpospec-pillar": "financials"
}