// ============================================
// Carrot BBS - Core Type Definitions
// 使用后端DTO类型，保持snake_case命名规范
// ============================================

// 导出DTO类型作为主要类型
export * from './dto';
export * from './schedule';
export * from './material';

// 兼容旧类型（用于内部组件）
import type {
  UserDTO,
  PostDTO,
  PostImageDTO,
  // 新的聊天系统类型
  ConversationType,
  MessageContentType,
  MessageStatus,
  MessageResponse,
  ConversationResponse,
  ConversationParticipantResponse,
  ConversationDetailResponse,
  CreateConversationRequest,
  SendMessageRequest,
  MarkReadRequest,
  UnreadCountResponse,
  ConversationUnreadCountResponse,
  ConversationListResponse,
  MessageListResponse,
  MessageSyncResponse,
  // Segment 类型
  SegmentType,
  MessageSegment,
  TextSegmentData,
  ImageSegmentData,
  VoiceSegmentData,
  VideoSegmentData,
  FileSegmentData,
  AtSegmentData,
  ReplySegmentData,
  FaceSegmentData,
  LinkSegmentData,
} from './dto';

// 重新导出新的聊天系统类型
export type {
  ConversationType,
  MessageContentType,
  MessageStatus,
  MessageResponse,
  ConversationResponse,
  ConversationParticipantResponse,
  ConversationDetailResponse,
  CreateConversationRequest,
  SendMessageRequest,
  MarkReadRequest,
  UnreadCountResponse,
  ConversationUnreadCountResponse,
  ConversationListResponse,
  MessageListResponse,
  MessageSyncResponse,
  // Segment 类型
  SegmentType,
  MessageSegment,
  TextSegmentData,
  ImageSegmentData,
  VoiceSegmentData,
  VideoSegmentData,
  FileSegmentData,
  AtSegmentData,
  ReplySegmentData,
  FaceSegmentData,
  LinkSegmentData,
};

// ============================================
// User Types
// ============================================

export type User = UserDTO;

export interface UserProfile extends User {
  favorites_count: number;
  liked_posts_count: number;
}

// ============================================
// Post Types
// ============================================

export type Post = PostDTO;
export type PostDetail = PostDTO;
export type PostImage = PostImageDTO;

// ============================================
// Vote Types
// ============================================

export type { VoteOptionDTO as VoteOption, VoteResultDTO as VoteResult, CreateVotePostRequest as CreateVotePostReq } from './dto';

export interface CreatePostInput {
  title: string;
  content: string;
  images?: string[]; // 本地图片路径或 base64
  channel_id?: string;
}

// ============================================
// Comment Types
// ============================================

// 评论图片
export interface CommentImage {
  url: string;
}

export interface Comment {
  id: string;
  post_id: string;
  user_id: string;
  parent_id: string | null;
  root_id?: string | null;
  content: string;
  images?: CommentImage[];
  likes_count: number;
  replies_count: number;
  is_liked?: boolean;
  author: User;
  replies?: Comment[];
  target_id?: string | null; // 被回复的评论ID，前端根据此ID找到被回复用户的昵称
  created_at: string;
}

export interface CreateCommentInput {
  postId: string;
  parentId?: string;
  content: string;
  images?: string[]; // 图片URL列表
  replyToUserId?: string;
}

// ============================================
// Notification Types
// ============================================

export type NotificationType =
  | 'like_post'
  | 'like_comment'
  | 'comment'
  | 'reply'
  | 'follow'
  | 'mention'
  | 'system';

export interface Notification {
  id: string;
  userId: string;
  type: NotificationType;
  title: string;
  content: string;
  data: {
    postId?: string;
    commentId?: string;
    userId?: string;
    [key: string]: unknown;
  };
  isRead: boolean;
  createdAt: string;
}

export interface NotificationBadge {
  total: number;
  likes: number;
  comments: number;
  follows: number;
  system: number;
}

// ============================================
// Message Types (New Chat System)
// ============================================

/**
 * 新版会话类型 - 使用雪花算法ID和seq机制
 */
export type Conversation = ConversationResponse;

/**
 * 新版消息类型 - 使用雪花算法ID和seq机制
 */
export type Message = MessageResponse;

// ============================================
// API Response Types
// ============================================

export interface ApiResponse<T> {
  success: boolean;
  data: T;
  message?: string;
}

export interface PaginatedResponse<T> {
  success: boolean;
  data: T[];
  pagination: {
    page: number;
    limit: number;
    total: number;
    hasMore: boolean;
    nextCursor?: string;
  };
}

export interface ApiError {
  success: false;
  error: {
    code: string;
    message: string;
    details?: Record<string, string>;
  };
}
