export type WorkbenchActor = {
  id: string;
  role?: string | null;
};

export type WorkbenchMode = "native-test" | "agentrun-native" | "temporal";

export type WorkbenchCommand =
  | { operation: "health" }
  | { operation: "session.create"; actor: WorkbenchActor; params: Record<string, unknown> }
  | { operation: "turn.submit"; actor: WorkbenchActor; params: Record<string, unknown>; traceId?: string }
  | { operation: "turn.cancel"; actor: WorkbenchActor; traceId: string; params?: Record<string, unknown> };

export type WorkbenchCommandResult = {
  ok: boolean;
  operation: WorkbenchCommand["operation"];
  mode: WorkbenchMode;
  data?: Record<string, unknown>;
  error?: { code: string; message: string; details?: unknown };
};

export type WorkbenchTurnInput = {
  actor: WorkbenchActor;
  traceId: string;
  sessionId: string;
  params: Record<string, unknown>;
};

export type WorkbenchActivityConfig = {
  startToCloseTimeoutMs: number;
  retryInitialIntervalMs: number;
  retryMaximumIntervalMs: number;
  retryMaximumAttempts: number;
};

export interface WorkbenchEventPublisher {
  publish(input: {
    traceId: string;
    sessionId: string;
    event: Record<string, unknown>;
  }): Promise<Record<string, unknown>>;
  close?(): Promise<void>;
}

export interface WorkbenchApplication {
  health(): Promise<Record<string, unknown>>;
  createSession(input: { actor: WorkbenchActor; params: Record<string, unknown> }): Promise<Record<string, unknown>>;
  admitTurn(input: WorkbenchTurnInput): Promise<WorkbenchTurnInput>;
  dispatchTurn(input: WorkbenchTurnInput): Promise<Record<string, unknown>>;
  cancelTurn(input: { actor: WorkbenchActor; traceId: string; params: Record<string, unknown> }): Promise<Record<string, unknown>>;
  snapshot?(): Promise<{ sessions: Record<string, Record<string, unknown>>; turns: Record<string, Record<string, unknown>> }>;
  close?(): Promise<void>;
}

export interface WorkbenchTemporalGateway {
  submit(input: WorkbenchTurnInput): Promise<{ workflowId: string; workflowRunId: string; reused: boolean }>;
  cancel(input: { actor: WorkbenchActor; traceId: string; params: Record<string, unknown> }): Promise<{ workflowId: string; workflowRunId: string; reused: boolean }>;
  close(): Promise<void>;
}
