export interface ChatConversation {
  id: string;
  companyId: string;
  title: string | null;
  agentId: string | null;
  pinnedAt: string | null;
  archivedAt: string | null;
  deletedAt: string | null;
  createdAt: string;
  updatedAt: string;
  parentConversationId: string | null;
  branchFromMessageId: string | null;
}

export interface ChatConversationListItem {
  id: string;
  companyId: string;
  title: string | null;
  agentId: string | null;
  pinnedAt: string | null;
  archivedAt: string | null;
  updatedAt: string;
  lastMessagePreview: string | null;
  parentConversationId: string | null;
  branchFromMessageId: string | null;
}

export interface ChatFile {
  id: string;
  companyId: string;
  conversationId: string | null;
  messageId: string | null;
  filename: string;
  originalFilename: string;
  mimeType: string;
  sizeBytes: number;
  objectKey: string;
  sha256: string;
  source: "user_upload" | "agent_generated";
  category: "image" | "document" | "code" | "other" | null;
  projectId: string | null;
  createdAt: string;
  updatedAt: string;
}

export interface ChatFileReference {
  id: string;
  fileId: string;
  conversationId: string;
  messageId: string | null;
  createdAt: string;
}

export interface ChatFileUploadResponse {
  file: ChatFile;
  contentPath: string;
}

export interface ChatFileListResponse {
  items: ChatFile[];
}

export interface ChatMessage {
  id: string;
  conversationId: string;
  role: "user" | "assistant" | "system";
  content: string;
  agentId: string | null;
  messageType: string | null;
  createdAt: string;
  updatedAt: string | null;
  files?: ChatFile[];
}

export interface ChatConversationListResponse {
  items: ChatConversationListItem[];
  hasMore: boolean;
}

export interface ChatMessageListResponse {
  items: ChatMessage[];
  hasMore: boolean;
}

export interface ChatMessageSearchResult {
  messageId: string;
  conversationId: string;
  conversationTitle: string | null;
  content: string;
  role: "user" | "assistant" | "system";
  agentId: string | null;
  createdAt: string;
  rank: number;
}

export interface ChatMessageSearchResponse {
  items: ChatMessageSearchResult[];
}

export interface ChatBookmark {
  id: string;
  companyId: string;
  messageId: string;
  conversationId: string;
  createdAt: string;
}

export interface ChatBookmarkWithMessage extends ChatBookmark {
  message: ChatMessage;
  conversationTitle: string | null;
}

export interface ChatBookmarkListResponse {
  items: ChatBookmarkWithMessage[];
}

export interface ChatBookmarkToggleResponse {
  bookmarked: boolean;
}

export interface ChatFileHistoryEntry {
  hash: string;
  date: string;
  message: string;
  author: string;
}

export interface ChatPlaceholderEntry {
  fileId: string;
  filename: string;
  description: string;
  createdAt: string;
  replacedByFileId?: string;
}
