// Generated by bynkc — do not edit by hand.
// context retry

import { Ok, Err, Some, None, type Result, type Option, type ValidationError, type DurableObjectState, type DurableObjectNamespace, StateRegistry, makeAgent } from "./runtime.js";

export interface TaskState {
  readonly retries: number;
  readonly done: boolean;
}

const __TaskRegistry = new StateRegistry();
function __zeroOfTaskState(): TaskState { return { retries: 3, done: false }; }

export class Task {
  state: DurableObjectState;
  constructor(state: DurableObjectState) {
    this.state = state;
  }

  private async loadState(): Promise<TaskState> {
    const stored = await this.state.storage.get<TaskState>("state");
    return stored ?? __zeroOfTaskState();
  }

  private async commitState(s: TaskState): Promise<void> {
    await this.state.storage.put("state", s);
  }

  async peek(deps: {}): Promise<Result<void, string>> {
    const currentState = await this.loadState();
    return Ok(undefined);
  }

}

export function __makeTask(key: string, env?: { TASK?: DurableObjectNamespace }): Task {
  return makeAgent(__TaskRegistry, env?.TASK, key, (state) => new Task(state));
}

export function __resetAgents(): void {
  __TaskRegistry.reset();
}

