import type {
  AgentQuestionRequest,
  AgentTodoUpdate,
} from "@/lib/chatStream";

export type ChatProgress = {
  id: string;
  phase: string;
  status: "running" | "completed" | "error";
  title: string;
  detail?: string;
  startedAt?: number;
  endedAt?: number;
  elapsedMs?: number;
  elapsedSnapshotAt?: number;
  durationMs?: number;
};

export type AgentArtifactKind = "chart" | "map" | "panel" | "tool";

export type AgentArtifact = {
  id: string;
  tool: string;
  kind: AgentArtifactKind;
  title: string;
  description?: string;
  params: Record<string, unknown>;
};

export type AgentPermissionStatus =
  | "pending"
  | "submitting"
  | "approved_once"
  | "approved_always"
  | "rejected"
  | "aborted"
  | "error";

export type AgentPermissionRequest = {
  requestId: string;
  sessionId: string;
  permission: string;
  patterns: string[];
  target?: string;
  always: string[];
  tool?: {
    messageID: string;
    callID: string;
  };
  createdAt: number;
  repliedAt?: number;
  status: AgentPermissionStatus;
  error?: string;
};

export type Message = {
  id: string;
  role: "user" | "assistant";
  content: string;
  isError?: boolean;
  progress?: ChatProgress[];
  artifacts?: AgentArtifact[];
  permissions?: AgentPermissionRequest[];
  questions?: AgentQuestionRequest[];
  todos?: AgentTodoUpdate;
};

export type Props = {
  open: boolean;
  onClose: () => void;
};

export type SpeechState = "idle" | "loading" | "playing" | "paused";

export type ChatSessionSummary = {
  id: string;
  title: string;
  createdAt: number;
  updatedAt: number;
  isStreaming?: boolean;
  runStatus?: string;
};

export type LoadedChatState = {
  sessionId?: string;
  title?: string;
  isTitleManuallyEdited?: boolean;
  messages: Message[];
  isStreaming?: boolean;
  runStatus?: string;
};
