// API response types from backend
export type ApiMemo = {
  id: string; // MongoDB ObjectId
  uid?: string; // User-defined unique ID (preferred for URLs)
  content: string;
  visibility?: string | null;
  tags?: string[];
  creator_id?: string;
  row_status?: string;   // "NORMAL" | "ARCHIVED"
  pinned?: boolean;
  create_time?: string;
  update_time?: string;
  display_time?: string;
  parent?: string | null; // ID of parent memo (if this is a comment)
  comment_count?: number; // Number of comments for this memo
  workspace_id?: string; // Workspace isolation: PERSONAL | AI_SALES_CRM
  is_read?: boolean; // Inbox read status: false = unread, true = read
};

export type ApiAttachment = {
  id: string;
  filename: string;
  url: string;
};

export type ApiShortcut = {
  id: string;
  name: string;
  filter: string;
};

export type ApiActivity = {
  id: string;
  type?: string | null;
  description?: string | null;
};

export type ApiIdentityProvider = {
  id: string;
  name: string;
  type?: string | null;
};

export type ApiInstanceInfo = {
  mode?: string | null;
  version?: string | null;
};

export type ApiUser = {
  id: string;
  email?: string | null;
  nickname?: string | null;
  // New fields from backend for proper user display
  username?: string | null;
  displayName?: string | null;
  avatarUrl?: string | null;
  name?: string | null;  // Resource name: users/{id}
};


// ====================== DOCUMENTS ======================
export type ApiDocument = {
  id: number;
  uid: string;
  creator_id: string;
  filename: string;
  original_filename: string;
  file_path: string;
  file_size: number;
  mime_type: string;
  workspace_id: string;
  status: 'PENDING' | 'PROCESSING' | 'COMPLETED' | 'FAILED';
  pages?: number;
  title?: string;
  content?: string;
  summary?: string;
  tags?: string[];
  ai_enhanced: boolean;
  error_message?: string;
  created_at: string;
  updated_at: string;
  processed_at?: string;
};

export type ApiDocumentList = {
  documents: ApiDocument[];
  total: number;
  workspace_filter?: string;
};

export type DocumentUploadResponse = {
  success: boolean;
  document: ApiDocument;
  message: string;
};

export type DocumentDeleteResponse = {
  success: boolean;
  message: string;
};

export type DocumentProcessRequest = {
  enhance_with_ai?: boolean;
  generate_summary?: boolean;
  extract_tags?: boolean;
};

export type DocumentImportRequest = {
  memo_title?: string;
  tags?: string[];
  visibility?: 'PRIVATE' | 'PROTECTED' | 'PUBLIC';
  create_as_memo?: boolean;
};


export type RequestOptions = {
  method?: string;
  body?: unknown;
  headers?: HeadersInit;
};

