export interface LoomBoxOptions {
  agent?: string;
  root?: string;
  bridge?: string;
}

export interface ContextOptions {
  agent?: string;
  view?: string;
  asOf?: string;
  sort?: string;
}

export type JsonRecord = Record<string, unknown>;

export class LoomError extends Error {
  code: string;
}

export class LoomBox {
  static create(task: string, options?: LoomBoxOptions): LoomBox;
  static open(task: string, options?: LoomBoxOptions): LoomBox;
  static list(options?: { root?: string }): JsonRecord[];
  readonly task: string;
  readonly agent: string;
  readonly eventsPath: string;
  events(): string;
  stateHash(): string;
  set(field: string, value: string): JsonRecord;
  fact(subject: string, predicate: string, object: string, source?: string): JsonRecord;
  observe(tool: string, status: string, summary: string, outputRef?: string): JsonRecord;
  decide(
    question: string,
    choice: string,
    rationale: string,
    options?: { supersedes?: string; dependsOn?: string[] },
  ): JsonRecord;
  artifact(name: string, uri: string, contentHash: string): JsonRecord;
  policy(key: string, value: string, options?: { enabled?: boolean; scope?: string }): JsonRecord;
  permission(agent: string, access: "read" | "write" | "none"): JsonRecord;
  context(options?: ContextOptions): JsonRecord;
  why(field: string): JsonRecord;
  next(options?: { agent?: string }): JsonRecord[];
  health(): JsonRecord;
  check(): JsonRecord;
  timeline(): JsonRecord[];
  causal(): JsonRecord[];
  audit(): string;
  merge(other: LoomBox): JsonRecord;
}

export default LoomBox;