export type MessageRole =
	| "user"
	| "assistant"
	| "system"
	| "tool_call"
	| "bash"
	| "thinking"
	| "compaction_summary"
	| "branch_summary";

export interface ContentBlock {
	type: string;
	text?: string;
	thinking?: string;
	data?: string;
	mimeType?: string;
	toolName?: string;
	name?: string;
	id?: string;
	toolCallId?: string;
	arguments?: unknown;
	args?: unknown;
	input?: unknown;
}

export interface ImageContent {
	type: "image";
	data: string;
	mimeType: string;
}

export interface RpcMessage {
	role: string;
	content?: string | ContentBlock[];
	command?: string;
	output?: string;
	exitCode?: number;
	cancelled?: boolean;
	truncated?: boolean;
	excludeFromContext?: boolean;
	summary?: string;
	toolCallId?: string;
}

export interface ToolCallBlock {
	type: "toolCall";
	toolName?: string;
	name?: string;
	id?: string;
	toolCallId?: string;
	arguments?: unknown;
	args?: unknown;
	input?: unknown;
}

export interface ChatMessage {
	id: string;
	role: MessageRole;
	content: string;
	images?: ImageContent[];
	toolCallId?: string;
	bashCommand?: string;
	bashExitCode?: number;
	bashExcludeFromContext?: boolean;
	streaming?: boolean;
}

export interface ModelInfo {
	provider: string;
	id: string;
	reasoning?: boolean;
	contextWindow?: number;
	thinkingLevelMap?: Record<string, string | null>;
}

export interface SessionSummary {
	path: string;
	name?: string;
	firstMessage?: string;
	messageCount?: number;
	modified?: string;
	created?: string;
}

export interface SessionHistoryPayload {
	session?: { id?: string | number; name?: string };
	messages?: RpcMessage[];
	error?: string;
}

export interface SessionState {
	error?: string;
	sessionId?: string | number;
	sessionName?: string;
	sessionFile?: string;
	model?: ModelInfo;
	thinkingLevel?: string;
	stats?: {
		tokens?: {
			input?: number;
			output?: number;
			cacheRead?: number;
			cacheWrite?: number;
		};
		cost?: number;
		contextUsage?: { percent?: number; contextWindow?: number };
	};
	autoCompactionEnabled?: boolean;
	isStreaming?: boolean;
	isCompacting?: boolean;
	turnIndex?: number;
}

export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh";

export const THINKING_LEVELS: ThinkingLevel[] = ["off", "minimal", "low", "medium", "high", "xhigh"];
