{
  "$defs": {
    "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"
    },
    "ReconKind": {
      "description": "Kind of reconciliation.",
      "enum": [
        "bank",
        "ar",
        "ap",
        "intercompany",
        "payroll",
        "tax",
        "inventory"
      ],
      "type": "string"
    },
    "ReconcStatus": {
      "description": "Outer reconciliation status (overall workflow stage).",
      "oneOf": [
        {
          "const": "open",
          "description": "Open — variance not yet cleared.",
          "type": "string"
        },
        {
          "const": "cleared",
          "description": "Cleared — variance reconciled to zero or to a documented residual.",
          "type": "string"
        },
        {
          "const": "escalated",
          "description": "Escalated — variance requires management attention.",
          "type": "string"
        }
      ]
    },
    "ReconcilingItem": {
      "description": "One reconciling line item.",
      "properties": {
        "amount": {
          "format": "double",
          "type": "number"
        },
        "description": {
          "type": "string"
        },
        "kind": {
          "$ref": "#/$defs/ReconcilingItemKind"
        },
        "resolving_entry": {
          "anyOf": [
            {
              "$ref": "#/$defs/PathRef"
            },
            {
              "type": "null"
            }
          ],
          "description": "PathRef into a JournalEntry that resolves this item, when posted."
        },
        "target_action": {
          "description": "Target action — e.g. \"post correcting JE in May\", \"follow up with\nvendor\", \"await bank settlement\".",
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "description",
        "amount",
        "kind"
      ],
      "type": "object"
    },
    "ReconcilingItemKind": {
      "description": "Item-level classification of a reconciling item.",
      "oneOf": [
        {
          "const": "timing",
          "description": "Timing difference (in-transit, GR/IR, etc.).",
          "type": "string"
        },
        {
          "const": "error",
          "description": "Posting error requiring correction.",
          "type": "string"
        },
        {
          "const": "unrecorded",
          "description": "Item not yet recorded in books.",
          "type": "string"
        },
        {
          "const": "fx",
          "description": "Foreign-exchange revaluation difference.",
          "type": "string"
        },
        {
          "const": "other",
          "description": "Other / explanatory.",
          "type": "string"
        }
      ]
    }
  },
  "$id": "https://corpospec.com/schemas/v0.16.0/reconciliation.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "Reconciliation record.",
  "properties": {
    "actual_balance": {
      "$ref": "#/$defs/MonetaryAmount",
      "description": "Per-external-statement actual balance (bank / vendor / tax\nauthority)."
    },
    "as_of": {
      "$ref": "#/$defs/IsoDate"
    },
    "entity": {
      "$ref": "#/$defs/PathRef"
    },
    "evidence": {
      "description": "Statement PDFs, screenshots — typically PathRefs into encrypted\ndocument storage.",
      "items": {
        "$ref": "#/$defs/PathRef"
      },
      "type": "array"
    },
    "expected_balance": {
      "$ref": "#/$defs/MonetaryAmount",
      "description": "Per-GL expected balance (the company's books)."
    },
    "id": {
      "$ref": "#/$defs/PathRef"
    },
    "kind": {
      "$ref": "#/$defs/ReconKind"
    },
    "note": {
      "type": [
        "string",
        "null"
      ]
    },
    "period": {
      "$ref": "#/$defs/PathRef"
    },
    "prepared_at": {
      "$ref": "#/$defs/IsoDate"
    },
    "prepared_by": {
      "$ref": "#/$defs/PathRef"
    },
    "reconciling_items": {
      "description": "Reconciling line items that explain the variance.",
      "items": {
        "$ref": "#/$defs/ReconcilingItem"
      },
      "type": "array"
    },
    "reviewed_at": {
      "anyOf": [
        {
          "$ref": "#/$defs/IsoDate"
        },
        {
          "type": "null"
        }
      ]
    },
    "reviewed_by": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ]
    },
    "status": {
      "$ref": "#/$defs/ReconcStatus"
    },
    "variance": {
      "$ref": "#/$defs/MonetaryAmount",
      "description": "Computed variance (`actual - expected`)."
    }
  },
  "required": [
    "id",
    "entity",
    "kind",
    "period",
    "as_of",
    "expected_balance",
    "actual_balance",
    "variance",
    "reconciling_items",
    "status",
    "prepared_by",
    "prepared_at"
  ],
  "title": "Reconciliation",
  "type": "object",
  "x-corpospec-pillar": "financials"
}