{
  "$defs": {
    "IsoDate": {
      "description": "ISO 8601 date (YYYY-MM-DD).",
      "format": "date",
      "type": "string"
    },
    "JournalRange": {
      "description": "Range of JournalEntry PathRefs that fed this trial balance.",
      "properties": {
        "first_entry": {
          "$ref": "#/$defs/PathRef"
        },
        "last_entry": {
          "$ref": "#/$defs/PathRef"
        }
      },
      "required": [
        "first_entry",
        "last_entry"
      ],
      "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"
    },
    "TrialBalanceLine": {
      "description": "One trial-balance line per active account.",
      "properties": {
        "account": {
          "$ref": "#/$defs/PathRef",
          "description": "PathRef into a CoA Account record."
        },
        "credit_total": {
          "description": "Sum of credits posted to this account in the trial-balance period.",
          "format": "double",
          "type": "number"
        },
        "debit_total": {
          "description": "Sum of debits posted to this account in the trial-balance period.",
          "format": "double",
          "type": "number"
        },
        "ending_balance": {
          "description": "Ending balance after the period. Sign follows the account's\nnormal-balance side.",
          "format": "double",
          "type": "number"
        }
      },
      "required": [
        "account",
        "debit_total",
        "credit_total",
        "ending_balance"
      ],
      "type": "object"
    }
  },
  "$id": "https://corpospec.com/schemas/v0.16.0/trial-balance.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "Trial-balance snapshot.",
  "properties": {
    "as_of": {
      "$ref": "#/$defs/IsoDate",
      "description": "Snapshot date."
    },
    "content_hash": {
      "description": "SHA-256 of canonicalised payload (excluding this field).",
      "type": "string"
    },
    "derived_from_journal_range": {
      "anyOf": [
        {
          "$ref": "#/$defs/JournalRange"
        },
        {
          "type": "null"
        }
      ],
      "description": "Range of journal entries that produced this trial balance."
    },
    "entity": {
      "$ref": "#/$defs/PathRef",
      "description": "Subject entity."
    },
    "generated_at": {
      "$ref": "#/$defs/IsoDate",
      "description": "When this snapshot was generated."
    },
    "id": {
      "$ref": "#/$defs/PathRef",
      "description": "PathRef identifier, conventionally\n`financials/trial-balances/<entity>-<period>-<as-of>`."
    },
    "lines": {
      "description": "One line per active GL account with non-zero activity in the\nperiod.",
      "items": {
        "$ref": "#/$defs/TrialBalanceLine"
      },
      "type": "array"
    },
    "note": {
      "description": "Free-form note.",
      "type": [
        "string",
        "null"
      ]
    },
    "period": {
      "$ref": "#/$defs/PathRef",
      "description": "PathRef into the AccountingPeriod this snapshot covers."
    }
  },
  "required": [
    "id",
    "entity",
    "period",
    "as_of",
    "lines",
    "content_hash",
    "generated_at"
  ],
  "title": "TrialBalance",
  "type": "object",
  "x-corpospec-pillar": "financials"
}