// AUTO-GENERATED -- DO NOT EDIT.
//
// This file is regenerated by `scripts/regen-bindings.sh` from the
// Rust DTOs in `crates/rustledger-wasm/src/types.rs`. Run the script
// after changing any DTO; CI fails if this file drifts from the
// generator output. See ADR-0004 (#1218) for the design.

/**
 * Amount value for serialization.
 */
export type AmountValue = {
  /**
   * The number as a string.
   */
  number: string;
  /**
   * The currency.
   */
  currency: string;
};

/**
 * An error with source location.
 *
 * **Renamed to `BeancountError` on the TS side** to avoid shadowing
 * the JS-builtin `Error` type. The Rust struct keeps the shorter
 * `Error` name for internal use; the rename is applied via
 * `#[ts(rename = ...)]` so consumers see a non-shadowing name.
 */
export type BeancountError = {
  /**
   * Error message.
   */
  message: string;
  /**
   * Line number (1-based). `null` when the error has no source
   * location (e.g. validation errors not tied to a span). Field is
   * always present on the wire (no `skip_serializing_if`); see the
   * struct-level `schemars(extend)` for the required-and-nullable
   * rationale. `range(min = 1)` enforces the 1-based documented
   * contract on the JSON Schema side (schemars defaults to
   * `minimum: 0` for u32).
   */
  line: number | null;
  /**
   * Column number (1-based). `null` when the error has no source
   * location. See `line` above for `range` rationale.
   */
  column: number | null;
  /**
   * Error severity.
   */
  severity: Severity;
};

/**
 * A cell value that serializes properly to JavaScript.
 *
 * Uses untagged serialization to produce clean JSON output.
 */
export type CellValue =
  | null
  | string
  | number
  | boolean
  | { number: string; currency: string }
  | { units: AmountValue; cost?: CostValue }
  | { positions: Array<PositionValue> }
  | Array<string>
  | Array<CellValue>
  | { [key in string]: CellValue };

/**
 * BQL completion suggestion for WASM.
 */
export type CompletionJson = {
  /**
   * The completion text to insert.
   */
  text: string;
  /**
   * Category: keyword, function, column, operator, literal.
   */
  category: string;
  /**
   * Optional description/documentation.
   */
  description?: string;
};

/**
 * The kind of a completion item.
 */
export type CompletionKind =
  | "keyword"
  | "account"
  | "accountsegment"
  | "currency"
  | "payee"
  | "date"
  | "text"
  | "tag"
  | "link";

/**
 * Result of BQL completion request.
 */
export type CompletionResultJson = {
  /**
   * List of completions.
   */
  completions: Array<CompletionJson>;
  /**
   * Current context for debugging.
   */
  context: string;
};

/**
 * Wire-format of the numeric component of a [`PostingCostJson`].
 *
 * Mirrors `rustledger_core::CostNumber` on the wire so JS consumers
 * see the same mutual exclusion the host enforces. Use the `kind`
 * field as the discriminator.
 */
export type CostNumberJson =
  | {
      kind: "per_unit";
      /**
       * Per-unit value.
       */
      value: string;
    }
  | {
      kind: "total";
      /**
       * Total value.
       */
      value: string;
    }
  | {
      kind: "per_unit_from_total";
      /**
       * Derived per-unit.
       */
      per_unit: string;
      /**
       * Source total.
       */
      total: string;
    };

/**
 * Cost value for serialization.
 */
export type CostValue = {
  /**
   * Cost per unit.
   */
  number: string;
  /**
   * Cost currency.
   */
  currency: string;
  /**
   * Acquisition date.
   */
  date?: string;
  /**
   * Lot label.
   */
  label?: string;
};

/**
 * A directive in JSON-serializable form.
 *
 * Each variant corresponds to a Beancount directive type, with fields
 * representing the directive's data in a JavaScript-friendly format.
 *
 * All variants carry a `meta` field with user-defined key/value
 * metadata from the source (issue #1168). Empty metadata serializes
 * as an absent field, so existing consumers continue to see the
 * pre-#1168 shape on directives without explicit metadata.
 */
export type DirectiveJson =
  | {
      type: "transaction";
      date: string;
      flag: string;
      /**
       * Optional payee. Mirrors FFI-WASI's shape: absent on the
       * wire when `None` (closes #1221).
       */
      payee?: string;
      /**
       * Optional narration. Empty narrations are normalized to
       * `None` in `convert.rs` so the field is absent on the wire
       * in the empty case -- matches FFI-WASI's pattern (#1221).
       */
      narration?: string;
      tags: Array<string>;
      links: Array<string>;
      postings: Array<PostingJson>;
      meta?: { [key in string]: MetaValueJson };
    }
  | {
      type: "balance";
      date: string;
      account: string;
      amount: AmountValue;
      /**
       * Explicit tolerance from the `~ 0.01` annotation, stringified.
       * Mirrors `rustledger_core::Balance::tolerance`.
       */
      tolerance?: string;
      meta?: { [key in string]: MetaValueJson };
    }
  | {
      type: "open";
      date: string;
      account: string;
      currencies: Array<string>;
      booking?: string;
      meta?: { [key in string]: MetaValueJson };
    }
  | { type: "close"; date: string; account: string; meta?: { [key in string]: MetaValueJson } }
  | { type: "commodity"; date: string; currency: string; meta?: { [key in string]: MetaValueJson } }
  | {
      type: "pad";
      date: string;
      account: string;
      source_account: string;
      meta?: { [key in string]: MetaValueJson };
    }
  | {
      type: "event";
      date: string;
      event_type: string;
      value: string;
      meta?: { [key in string]: MetaValueJson };
    }
  | {
      type: "note";
      date: string;
      account: string;
      comment: string;
      meta?: { [key in string]: MetaValueJson };
    }
  | {
      type: "document";
      date: string;
      account: string;
      path: string;
      /**
       * Tags attached to the document directive (issue #1144).
       */
      tags?: Array<string>;
      /**
       * Links attached to the document directive (issue #1144).
       */
      links?: Array<string>;
      meta?: { [key in string]: MetaValueJson };
    }
  | {
      type: "price";
      date: string;
      currency: string;
      amount: AmountValue;
      meta?: { [key in string]: MetaValueJson };
    }
  | {
      type: "query";
      date: string;
      name: string;
      query_string: string;
      meta?: { [key in string]: MetaValueJson };
    }
  | {
      type: "custom";
      date: string;
      custom_type: string;
      /**
       * Positional values after the `custom TYPE` keyword. Each
       * entry is a [`TypedValueJson`] (`{type, value}`) — the
       * tagged shape preserves the host `MetaValue` variant tag so
       * JS consumers can distinguish a `Date` from a `String` from
       * an `Account` (closes #1207). Mirrors FFI-WASI's
       * `Vec<TypedValue>` exactly.
       */
      values?: Array<TypedValueJson>;
      meta?: { [key in string]: MetaValueJson };
    };

/**
 * A completion item for Beancount source editing.
 */
export type EditorCompletion = {
  /**
   * The label to display in the completion list.
   */
  label: string;
  /**
   * The kind of completion item.
   */
  kind: CompletionKind;
  /**
   * A human-readable string with additional information.
   */
  detail?: string;
  /**
   * The text to insert when this completion is selected.
   */
  insert_text?: string;
};

/**
 * Result of a completion request.
 */
export type EditorCompletionResult = {
  /**
   * The completions.
   */
  completions: Array<EditorCompletion>;
  /**
   * The detected context.
   */
  context: string;
};

/**
 * A document symbol for the outline view.
 */
export type EditorDocumentSymbol = {
  /**
   * The name of this symbol.
   */
  name: string;
  /**
   * More detail for this symbol.
   */
  detail?: string;
  /**
   * The kind of this symbol.
   */
  kind: SymbolKind;
  /**
   * The range enclosing this symbol.
   */
  range: EditorRange;
  /**
   * Children of this symbol (e.g., postings in a transaction).
   */
  children?: Array<EditorDocumentSymbol>;
  /**
   * Whether this symbol is deprecated (e.g., closed account).
   */
  deprecated?: boolean;
};

/**
 * Hover information for a symbol.
 */
export type EditorHoverInfo = {
  /**
   * The hover content (Markdown formatted).
   */
  contents: string;
  /**
   * The range of the hovered symbol (optional).
   */
  range?: EditorRange;
};

/**
 * A location in the document.
 */
export type EditorLocation = {
  /**
   * Line number (0-based).
   */
  line: number;
  /**
   * Character offset (0-based).
   */
  character: number;
};

/**
 * A range in the document.
 */
export type EditorRange = {
  /**
   * Start line (0-based).
   */
  start_line: number;
  /**
   * Start character (0-based).
   */
  start_character: number;
  /**
   * End line (0-based).
   */
  end_line: number;
  /**
   * End character (0-based).
   */
  end_character: number;
};

/**
 * A reference to a symbol in the document.
 */
export type EditorReference = {
  /**
   * The range of this reference.
   */
  range: EditorRange;
  /**
   * The kind of reference.
   */
  kind: ReferenceKind;
  /**
   * Whether this is the defining occurrence.
   */
  is_definition: boolean;
  /**
   * Human-readable context (e.g., directive type).
   */
  context?: string;
};

/**
 * Result of a find-references request.
 */
export type EditorReferencesResult = {
  /**
   * The symbol being searched for.
   */
  symbol: string;
  /**
   * The kind of symbol.
   */
  kind: ReferenceKind;
  /**
   * All references found.
   */
  references: Array<EditorReference>;
};

/**
 * Result of formatting.
 */
export type FormatResult = {
  /**
   * Formatted source (if successful). Emitted as JSON `null` on
   * failure; no `skip_serializing_if`, so the field is always
   * present on the wire.
   */
  formatted: string | null;
  /**
   * Format errors.
   */
  errors: Array<BeancountError>;
};

/**
 * A parsed Beancount ledger.
 *
 * **Renamed to `LedgerJson` on the TS side** to avoid colliding with
 * the wasm-bindgen-exported `Ledger` class (the runtime wrapper that
 * owns the parsed data). `LedgerJson` is the wire shape; `Ledger` is
 * the class consumers instantiate via `Ledger.fromFiles(...)`. The
 * Rust struct keeps the shorter name for internal use; the rename
 * is applied via `#[ts(rename = ...)]`.
 */
export type LedgerJson = {
  /**
   * All directives in the ledger.
   */
  directives: Array<DirectiveJson>;
  /**
   * Ledger options.
   */
  options: LedgerOptions;
};

/**
 * Ledger options.
 */
export type LedgerOptions = {
  /**
   * Operating currencies.
   */
  operating_currencies: Array<string>;
  /**
   * Ledger title. Emitted as JSON `null` when no title is set
   * (no `skip_serializing_if`; field is always present on the
   * wire). TS: `string | null`, not `title?`. The required-and-
   * nullable wire contract is enforced via the `schemars(extend)`
   * on the struct itself; see `ParseResult` for the rationale.
   */
  title: string | null;
};

/**
 * Metadata-value wire format for WASM consumers.
 *
 * **JSON output is byte-equivalent to FFI-WASI's
 * `meta_value_to_json`** — JS clients writing portable code see
 * identical metadata values from both bindings. The Rust-side
 * types are independent though: FFI-WASI emits
 * `serde_json::Value` (untyped), this crate emits a typed enum.
 * Unifying the source-of-truth is tracked by issue #1200 item 2.
 *
 * The host's [`rustledger_core::MetaValue`] is richer than the wire
 * type — `Account`/`Currency`/`Tag`/`Link`/`Date`/`Number` all
 * flatten to JSON strings here, matching FFI-WASI behavior. JS
 * consumers that need the strong type info should query the host
 * via a typed API; this enum is the lossy-but-portable view.
 *
 * Untagged on the wire: `"hello"` serializes as a string,
 * `true` as a boolean, `null` as null, and an [`AmountValue`]
 * `{number,currency}` as a plain object. The TypeScript union is
 * `Record<string, string | boolean | {number, currency} | null>` —
 * no raw JSON number arm because `MetaValue::Number` (`Decimal`)
 * stringifies to preserve precision. Issue #1168 proposed
 * `string | number | boolean | null`; we substitute the
 * `{number,currency}` shape for `number` so cost-bearing metadata
 * round-trips cleanly and so JS numeric literals don't silently
 * alias into the wire (see the `meta_value_json_rejects_raw_json_number`
 * test).
 */
export type MetaValueJson =
  | string
  | boolean
  | {
      /**
       * The decimal quantity, stringified for precision.
       */
      number: string;
      /**
       * The currency code.
       */
      currency: string;
    }
  | null;

/**
 * Result of pad expansion.
 */
export type PadResult = {
  /**
   * The original directives, verbatim. `Pad` directives are NOT
   * removed — consumers wanting a pads-removed view should
   * filter on directive type. The `padding_transactions` field
   * carries the synthesized P-flag transactions separately.
   */
  directives: Array<DirectiveJson>;
  /**
   * Generated padding transactions (synthesized P-flag, one per
   * pad-balance pair, multi-currency pads produce one per
   * currency).
   */
  padding_transactions: Array<DirectiveJson>;
  /**
   * Pad processing errors (e.g. unused pads with no matching
   * balance assertion).
   */
  errors: Array<BeancountError>;
};

/**
 * Result of parsing a Beancount file.
 */
export type ParseResult = {
  /**
   * The parsed ledger (if successful). Emitted as JSON `null` when
   * parsing failed entirely; no `skip_serializing_if`, so the field
   * is always present on the wire (TS: `Ledger | null`, not
   * `ledger?`). See the `#[schemars(extend(...))]` on the struct
   * itself for the "required-and-nullable" wire-contract enforcement.
   */
  ledger: LedgerJson | null;
  /**
   * Parse errors.
   */
  errors: Array<BeancountError>;
};

/**
 * Plugin information.
 */
export type PluginInfo = {
  /**
   * Plugin name.
   */
  name: string;
  /**
   * Plugin description.
   */
  description: string;
};

/**
 * Result of running a plugin.
 */
export type PluginResult = {
  /**
   * Modified directives.
   */
  directives: Array<DirectiveJson>;
  /**
   * Plugin errors/warnings.
   */
  errors: Array<BeancountError>;
};

/**
 * Position value for serialization.
 */
export type PositionValue = {
  /**
   * The units.
   */
  units: AmountValue;
};

/**
 * A posting cost in JSON-serializable form.
 */
export type PostingCostJson = {
  /**
   * Cost number (per-unit, total, or post-booking pair).
   */
  number?: CostNumberJson;
  /**
   * Cost currency.
   */
  currency?: string;
  /**
   * Acquisition date.
   */
  date?: string;
  /**
   * Lot label.
   */
  label?: string;
};

/**
 * A posting in JSON-serializable form.
 */
export type PostingJson = {
  /**
   * Account name.
   */
  account: string;
  /**
   * Units (amount).
   */
  units?: AmountValue;
  /**
   * Cost specification.
   */
  cost?: PostingCostJson;
  /**
   * Price annotation.
   */
  price?: AmountValue;
  /**
   * Posting-level flag (e.g., `"!"` for pending). Mirrors
   * `rustledger_core::Posting::flag`.
   */
  flag?: string;
  /**
   * Posting-level metadata (issue #1168). Empty when the posting
   * has no explicit metadata.
   */
  meta?: { [key in string]: MetaValueJson };
};

/**
 * Result of a BQL query.
 */
export type QueryResult = {
  /**
   * Column names.
   */
  columns: Array<string>;
  /**
   * Result rows.
   */
  rows: Array<Array<CellValue>>;
  /**
   * Query errors.
   */
  errors: Array<BeancountError>;
};

/**
 * The kind of symbol being referenced.
 */
export type ReferenceKind = "account" | "currency" | "payee";

/**
 * Error severity level.
 */
export type Severity = "error" | "warning";

/**
 * The kind of a symbol.
 */
export type SymbolKind =
  | "transaction"
  | "account"
  | "balance"
  | "commodity"
  | "posting"
  | "pad"
  | "event"
  | "note"
  | "document"
  | "price"
  | "query"
  | "custom";

/**
 * Result of validation.
 */
export type ValidationResult = {
  /**
   * Whether the ledger is valid.
   */
  valid: boolean;
  /**
   * Validation errors.
   */
  errors: Array<BeancountError>;
};

/**
 * Tagged-union value used in `DirectiveJson::Custom`'s `values` field
 * (issue #1207). Narrowed discriminated union -- `switch (v.type)` (or
 * `if (v.type === "amount")`) narrows `v.value` to the right payload
 * shape.
 *
 * **Hand-tuned override** of the auto-generated `TypedValueJson` -- the
 * Rust DTO is a struct, not a tagged enum, so ts-rs can't emit the
 * narrowing on its own. See ADR-0004 (#1218).
 */
export type TypedValueJson =
  | { type: "string"; value: string }
  | { type: "account"; value: string }
  | { type: "currency"; value: string }
  | { type: "tag"; value: string }
  | { type: "link"; value: string }
  | { type: "date"; value: string }
  | { type: "number"; value: string }
  | { type: "bool"; value: boolean }
  | { type: "amount"; value: { number: string; currency: string } }
  | { type: "null"; value: null };
