/**
 * Auth, Notification & System DTOs
 */

import type { UserDTO } from './user';
import type { MessageSegment, AtSegmentData, FileSegmentData, FaceSegmentData, LinkSegmentData, PostRefSegmentData } from './message';

// ==================== Auth DTOs ====================

export interface LoginDTO {
  user: UserDTO;
  access_token: string;
  refresh_token: string;
}

export interface RegisterDTO {
  user: UserDTO;
  access_token: string;
  refresh_token: string;
}

export interface RefreshTokenDTO {
  access_token: string;
  refresh_token: string;
}

// ==================== Notification DTOs ====================

export interface NotificationDTO {
  id: string;
  user_id: string;
  type: string;
  title: string;
  content: string;
  data: string;
  is_read: boolean;
  created_at: string;
}

// ==================== System Message Types ====================

export type MessageCategory = 'chat' | 'notification' | 'announcement' | 'marketing';

export type SystemMessageType =
  | 'like_post'
  | 'like_comment'
  | 'like_reply'
  | 'favorite_post'
  | 'comment'
  | 'reply'
  | 'follow'
  | 'mention'
  | 'system'
  | 'announcement'
  | 'announce'
  | 'group_invite'
  | 'group_join_apply'
  | 'group_join_approved'
  | 'group_join_rejected';

export interface SystemMessageExtraData {
  actor_id?: number;
  actor_id_str?: string;
  actor_name?: string;
  avatar_url?: string;
  target_id?: string;
  target_title?: string;
  target_type?: string;
  action_url?: string;
  action_time?: string;
  group_id?: string;
  group_name?: string;
  group_avatar?: string;
  group_description?: string;
  flag?: string;
  request_type?: 'invite' | 'join_apply';
  request_status?: 'pending' | 'accepted' | 'rejected' | 'cancelled' | 'expired';
  reason?: string;
  target_user_id?: string;
  target_user_name?: string;
  target_user_avatar?: string;
  operator_id?: number;
  operator_name?: string;
  operator_avatar?: string;
  post_id?: number;
  post_title?: string;
  comment_id?: number;
  comment_preview?: string;
  reply_id?: number;
}

export interface SystemMessageResponse {
  id: string;
  sender_id: string;
  receiver_id: string;
  content: string;
  category: MessageCategory;
  system_type: SystemMessageType;
  extra_data?: SystemMessageExtraData;
  is_read?: boolean;
  created_at: string;
}

export interface SystemMessageListResponse {
  messages: SystemMessageResponse[];
  total: number;
  has_more: boolean;
}

export interface SystemUnreadCountResponse {
  unread_count: number;
}

// ==================== Push Device Types ====================

export type DeviceType = 'ios' | 'android' | 'web';

export interface DeviceTokenResponse {
  id: number;
  device_id: string;
  device_type: DeviceType;
  is_active: boolean;
  device_name?: string;
  last_used_at: string;
  created_at: string;
}

export interface RegisterDeviceRequest {
  device_id: string;
  device_type: DeviceType;
  push_token?: string;
  device_name?: string;
}

export interface PushRecordResponse {
  id: number;
  message_id: number;
  push_channel: string;
  push_status: string;
  retry_count: number;
  pushed_at?: string;
  delivered_at?: string;
  created_at: string;
}

// ==================== WS Event Types ====================

export type WSEventType = 'message' | 'notice' | 'request' | 'meta';
export type WSDetailType = 'private' | 'group' | 'follow' | 'like' | 'comment' | 'request' | 'typing' | 'heartbeat' | 'read';

export interface WSSegment {
  type: string;
  data: Record<string, any>;
}

export interface WSEvent {
  id: string;
  time: number;
  type: WSEventType;
  detail_type: WSDetailType;
  seq: string;
  message?: WSSegment[];
  conversation_id: string;
}

// ==================== Verification DTOs ====================

import type { VerificationStatus, UserIdentity } from './user';

export type { VerificationStatus, UserIdentity } from './user';

export interface VerificationStatusDTO {
  verification_status: VerificationStatus;
  identity?: UserIdentity;
  has_pending_request?: boolean;
  rejected_reason?: string;
  verified_at?: string;
  latest_record?: {
    id: string;
    reject_reason?: string;
    real_name?: string;
    department?: string;
    created_at?: string;
  };
}

export interface VerificationRecordDTO {
  id: string;
  user_id: string;
  identity: UserIdentity;
  status: VerificationStatus;
  real_name: string;
  student_id?: string;
  employee_id?: string;
  department?: string;
  proof_materials: string;
  reviewer_id?: string;
  review_note?: string;
  created_at: string;
  updated_at: string;
}

export interface SubmitVerificationRequest {
  identity: UserIdentity;
  real_name: string;
  student_id?: string;
  employee_id?: string;
  department?: string;
  proof_materials: string;
}