type ChatTimeTimelineRole = 'assistant' | 'tool' | 'user';
type ChatTimeToolStatus = 'TOOL_CALL' | 'TOOL_RESULT';
type ChatTimeThinkingStatus = 'end' | 'thinking';

interface ChatTimeRoundMeta {
  messageKind?: string;
  roundId?: number | string;
  roundNo?: number;
  selectedVariantIndex?: number;
  switchable?: boolean;
  variantCount?: number;
  variantIndex?: number;
}

interface ChatTimeTimelineItemBase {
  created: number | string;
  id: string;
  loading?: boolean;
  messageKind?: string;
  placement: 'end' | 'start';
  roundId?: string;
  roundNo?: number;
  role: ChatTimeTimelineRole;
  selectedVariantIndex?: number;
  senderName?: string;
  switchable?: boolean;
  typing?: boolean;
  variantCount?: number;
  variantIndex?: number;
}

interface ChatTimeAssistantThinkingSegment {
  content: string;
  expanded: boolean;
  id: string;
  status: ChatTimeThinkingStatus;
  type: 'thinking';
}

interface ChatTimeAssistantTextSegment {
  content: string;
  id: string;
  type: 'text';
}

type ChatTimeAssistantSegment =
  | ChatTimeAssistantTextSegment
  | ChatTimeAssistantThinkingSegment;

interface ChatTimeAssistantItem extends ChatTimeTimelineItemBase {
  content: string;
  role: 'assistant';
  segments: ChatTimeAssistantSegment[];
}

interface ChatTimeToolItem extends ChatTimeTimelineItemBase {
  arguments?: string;
  content: string;
  name: string;
  result?: string;
  role: 'tool';
  status: ChatTimeToolStatus;
  toolCallId: string;
}

interface ChatTimeUserItem extends ChatTimeTimelineItemBase {
  content: string;
  role: 'user';
}

type ChatTimeTimelineItem =
  | ChatTimeAssistantItem
  | ChatTimeToolItem
  | ChatTimeUserItem;

interface ChatTimeHistoryRecord {
  chains?: Array<Record<string, any>>;
  content?: string;
  contentPayload?: null | Record<string, any>;
  contentText?: string;
  created?: number | string;
  id?: number | string;
  loading?: boolean;
  placement?: 'end' | 'start';
  role?: string;
  roundId?: number | string;
  roundNo?: number;
  selectedVariantIndex?: number;
  senderName?: string;
  senderRole?: string;
  switchable?: boolean;
  typing?: boolean;
  variantCount?: number;
  variantIndex?: number;
  messageKind?: string;
}

interface ChatTimeToolMutationPayload extends ChatTimeRoundMeta {
  created?: number | string;
  name?: string;
  regenerate?: boolean;
  result?: any;
  toolCallId?: string;
  value?: any;
}

export type {
  ChatTimeAssistantItem,
  ChatTimeAssistantSegment,
  ChatTimeAssistantTextSegment,
  ChatTimeAssistantThinkingSegment,
  ChatTimeHistoryRecord,
  ChatTimeRoundMeta,
  ChatTimeThinkingStatus,
  ChatTimeTimelineItem,
  ChatTimeTimelineItemBase,
  ChatTimeTimelineRole,
  ChatTimeToolItem,
  ChatTimeToolMutationPayload,
  ChatTimeToolStatus,
  ChatTimeUserItem,
};
