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

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

export type Light =
    { readonly tag: "Red" }
  | { readonly tag: "Green" };

export const Light = {
  Red: { tag: "Red" } as Light,
  Green: { tag: "Green" } as Light,
};

export interface SignalState {
  readonly colour: Light;
}

const __SignalRegistry = new StateRegistry();
function __zeroOfSignalState(): SignalState { return { colour: Light.Red }; }

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

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

  private async commitState(s: SignalState): 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 __makeSignal(key: string, env?: { SIGNAL?: DurableObjectNamespace }): Signal {
  return makeAgent(__SignalRegistry, env?.SIGNAL, key, (state) => new Signal(state));
}

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

