// src/layer/liveZone.ts
export type LiveZoneReason =
  | "latest-turn"
  | "frozen-tool-result"
  | "historical-turn"
  | "provider-unsupported";

export interface LiveZoneDecision {
  readonly mutable: boolean;
  readonly reason: LiveZoneReason;
}

export interface LiveZoneInput {
  readonly toolCallId?: string;
  readonly isLatestTurn: boolean;
  readonly frozenBytes: ReadonlyMap<string, string>;
  readonly providerSupportsTools: boolean;
}

export function decideToolResultLiveZone(input: LiveZoneInput): LiveZoneDecision {
  if (!input.providerSupportsTools) {
    return { mutable: false, reason: "provider-unsupported" };
  }

  if (!input.isLatestTurn) {
    return { mutable: false, reason: "historical-turn" };
  }

  if (input.toolCallId !== undefined && input.frozenBytes.has(input.toolCallId)) {
    return { mutable: false, reason: "frozen-tool-result" };
  }

  return { mutable: true, reason: "latest-turn" };
}
