declare namespace AuthAPI {
  // 用户信息
  interface UserInfo {
    _id: string;
    userId: number;
    userID?: number; // 兼容 API 返回的大写字段
    username: string;
    email: string;
    emailVerified: boolean;
    googleId?: string;
    googleData?: {
      email: string;
      name: string;
      givenName: string;
      picture: string;
    };
    loginMethods: string[];
    roles: string[];
    referralCode: string;
    profile: {
      nickname: string;
      avatar: string;
    };
    status: 'active' | 'disabled' | 'locked';
    lastLogin?: string;
    createdAt: string;
    updatedAt: string;
  }

  // GET /api/auth/profile 响应数据（直接返回用户对象）
  interface ProfileData {
    userID: number;
    username: string;
    email: string;
    profile: {
      nickname: string;
      avatar: string;
    };
    roles: string[];
    referralCode: string;
    hasReferrer: boolean;
    referredByCode?: string;
    status: string;
    lastLogin?: string;
    createdAt: string;
    // 兼容其他可能的字段
    _id?: string;
    userId?: number;
  }

  // Token 信息
  interface Tokens {
    accessToken: string;
    refreshToken: string;
    accessTokenExpiry: string;
    refreshTokenExpiry: string;
  }

  // 通用响应结构
  interface Response<T = any> {
    success: boolean;
    message: string;
    data?: T;
    error?: {
      code: string;
      details?: Record<string, any>;
    };
  }

  // 预注册请求参数
  interface PreRegisterParams {
    username: string;
    password: string;
    email: string;
    nickname?: string;
    referralCode?: string;
    language?: 'zh' | 'en';
  }

  // 预注册响应数据
  interface PreRegisterData {
    email: string;
    expiresIn: string;
  }

  // 重发验证码请求参数
  interface ResendCodeParams {
    email: string;
    language?: 'zh' | 'en';
  }

  // 验证注册请求参数
  interface VerifyRegisterParams {
    email: string;
    code: string;
  }

  // 验证注册响应数据
  interface VerifyRegisterData {
    user: UserInfo;
    tokens: Tokens;
  }

  // 预登录请求参数
  interface PreLoginParams {
    email: string;
    password: string;
    language?: 'zh' | 'en';
  }

  // 预登录响应数据
  interface PreLoginData {
    email: string;
    expiresIn: string;
  }

  // 验证登录请求参数
  interface VerifyLoginParams {
    email: string;
    code: string;
  }

  // 验证登录响应数据
  interface VerifyLoginData {
    user: UserInfo;
    tokens: Tokens;
  }

  // Google 登录请求参数
  interface GoogleLoginParams {
    idToken?: string;
    accessToken?: string;
    referralCode?: string;
  }

  // Google 登录响应数据
  interface GoogleLoginData {
    user: UserInfo;
    tokens: Tokens;
  }

  // 忘记密码请求参数
  interface ForgotPasswordParams {
    email: string;
    language?: 'zh' | 'en';
  }

  // 重置密码请求参数
  interface ResetPasswordParams {
    email: string;
    code: string;
    newPassword: string;
  }

  // 刷新 Token 请求参数
  interface RefreshTokenParams {
    refreshToken: string;
  }

  // 刷新 Token 响应数据
  interface RefreshTokenData {
    accessToken: string;
    accessTokenExpiry: string;
  }

  // 修改用户信息请求参数
  interface UpdateProfileParams {
    nickname?: string;
    avatar?: string;
  }

  // 修改密码请求参数
  interface ChangePasswordParams {
    oldPassword: string;
    newPassword: string;
    logoutOtherDevices?: boolean;
  }

  // 修改密码响应数据
  interface ChangePasswordData {
    loggedOutOtherDevices: boolean;
  }

  // 邮箱状态响应数据
  interface EmailStatusData {
    hasEmail: boolean;
    email: string | null;
    emailVerified: boolean;
    pendingVerification: string | null;
  }

  // 发送邮箱验证码请求参数
  interface SendEmailCodeParams {
    email: string;
    language?: 'zh' | 'en';
  }

  // 发送邮箱验证码响应数据
  interface SendEmailCodeData {
    email: string;
    expiresIn: string;
    remaining: number;
  }

  // 更换邮箱请求参数 - 验证当前邮箱
  interface VerifyCurrentEmailParams {
    action: 'verify-current';
    currentCode: string;
  }

  // 更换邮箱请求参数 - 绑定新邮箱
  interface BindNewEmailParams {
    action: 'bind-new';
    newEmail: string;
    newCode: string;
  }

  // 验证当前邮箱响应数据
  interface VerifyCurrentEmailData {
    currentEmailVerified: boolean;
    expiresIn: string;
  }

  // 绑定新邮箱响应数据
  interface BindNewEmailData {
    user: UserInfo;
  }

  // 文件上传响应数据
  interface UploadFileData {
    filename: string;
    originalName: string;
    size: number;
    mimetype: string;
    url: string;
  }

  // 个人 API Key 相关类型
  interface ApiKeyInfo {
    id: string;
    apiKey: string;
    name: string;
    ipWhitelist?: string[];
    status: 'active' | 'revoked';
    lastUsedAt?: string;
    createdAt?: string;
  }

  // 创建 API Key 请求参数
  interface CreateApiKeyParams {
    name: string;
    ipWhitelist?: string[];
  }

  // 创建 API Key 响应数据
  interface CreateApiKeyData {
    id: string;
    apiKey: string;
    secret: string;
    name: string;
  }

  // 获取 API Key 列表响应数据
  interface ApiKeyListData {
    keys: ApiKeyInfo[];
    total: number;
  }

  // ============ 会话管理相关类型 ============

  // 设备信息
  interface DeviceInfo {
    deviceId?: string;
    deviceName?: string;
    deviceType: 'desktop' | 'mobile' | 'tablet' | 'unknown';
    os: string;
    osVersion?: string;
    browser: string;
    browserVersion?: string;
    userAgent?: string;
  }

  // 位置信息
  interface LocationInfo {
    country?: string;
    countryCode?: string;
    region?: string;
    city?: string;
    latitude?: number;
    longitude?: number;
  }

  // 会话信息
  interface SessionInfo {
    id: string;
    userId: string;
    tokenJti: string;
    deviceInfo: DeviceInfo;
    ipAddress: string;
    location?: LocationInfo;
    loginMethod: 'password' | 'google' | 'apikey';
    isActive: boolean;
    isCurrent: boolean;
    lastActiveAt: string;
    createdAt: string;
    expiresAt: string;
  }

  // 获取会话列表请求参数
  interface GetSessionsParams {
    page?: number;
    pageSize?: number;
    active?: boolean;
  }

  // 获取会话列表响应数据
  interface SessionListData {
    sessions: SessionInfo[];
    total: number;
    page: number;
    pageSize: number;
    totalPages: number;
  }

  // 获取活跃会话数响应数据
  interface SessionCountData {
    activeCount: number;
  }

  // 登录历史记录
  interface LoginHistoryRecord {
    id: string;
    userId: string;
    sessionId?: string;
    deviceInfo: DeviceInfo;
    ipAddress: string;
    location?: LocationInfo;
    loginMethod: 'password' | 'google' | 'apikey';
    status: 'success' | 'failed';
    failReason?: string;
    createdAt: string;
  }

  // 获取登录历史请求参数
  interface GetLoginHistoryParams {
    page?: number;
    pageSize?: number;
    status?: 'success' | 'failed';
    startDate?: string;
    endDate?: string;
  }

  // 获取登录历史响应数据
  interface LoginHistoryData {
    records: LoginHistoryRecord[];
    total: number;
    page: number;
    pageSize: number;
    totalPages: number;
  }

  // 撤销其他会话响应数据
  interface RevokeOthersData {
    revokedCount: number;
  }

  // ============ 操作日志相关类型 ============

  // Auth 操作类型
  type AuthOperationType =
    | 'login'
    | 'logout'
    | 'register'
    | 'pre_login'
    | 'pre_register'
    | 'google_login'
    | 'send_email_code'
    | 'verify_email'
    | 'send_verify_code'
    | 'verify_code'
    | 'change_password'
    | 'forgot_password'
    | 'reset_password'
    | 'refresh_token'
    | 'profile_update'
    | 'session_revoke'
    | 'kyc_submit'
    | 'kyc_review'
    | 'api_key_create'
    | 'api_key_revoke'
    | 'referral_bind'
    | 'commission_claim'
    | 'admin_query'
    | 'admin_action'
    | 'query'
    | 'action';

  // Auth 操作日志记录
  interface AuthOperationLog {
    id: number;
    user_id: number;
    ip: string;
    method: string;
    path: string;
    operation_type: AuthOperationType;
    detail: Record<string, any>;
    status_code: number;
    duration_ms: number;
    user_agent: string;
    created_at: string;
  }

  // 获取 Auth 操作日志参数
  interface GetAuthOperationLogsParams {
    page?: number;
    page_size?: number;
    user_id?: number;
    operation_type?: AuthOperationType;
    method?: string;
    path?: string;
    ip?: string;
    status_code?: number;
    start_time?: string;
    end_time?: string;
  }

  // 获取 Auth 操作日志响应
  interface GetAuthOperationLogsResponse {
    success: boolean;
    message: string;
    data: {
      list: AuthOperationLog[];
      total: number;
      page: number;
      pages: number;
    };
  }

  // ============ 每日统计相关类型 ============

  // 每日活跃统计项
  interface DailyActivityStat {
    date: string;
    active_users: number;
    total_operations: number;
  }

  // 获取每日活跃统计参数
  interface GetDailyStatsParams {
    start_date?: string;
    end_date?: string;
  }

  // 获取每日活跃统计响应
  interface GetDailyStatsResponse {
    success: boolean;
    message: string;
    data: {
      list: DailyActivityStat[];
      start_date: string;
      end_date: string;
    };
  }

  // 每日返佣统计项
  interface DailyCommissionStat {
    date: string;
    total_amount: number;
    total_count: number;
    claimed_amount: number;
    claimed_count: number;
    pending_amount: number;
    pending_count: number;
    direct_amount: number;
    level_diff_amount: number;
    team_bonus_amount: number;
    card_activated_amount: number;
    recharge_fee_amount: number;
  }

  // 获取每日返佣统计参数
  interface GetDailyCommissionStatsParams {
    start_date?: string;
    end_date?: string;
  }

  // 获取每日返佣统计响应
  interface GetDailyCommissionStatsResponse {
    success: boolean;
    message: string;
    data: {
      list: DailyCommissionStat[];
      start_date: string;
      end_date: string;
    };
  }

  // 重算统计数据参数
  interface RecalculateStatsParams {
    date?: string;
    start_date?: string;
    end_date?: string;
    type?: 'activity' | 'commission' | 'all';
  }

  // 重算统计数据响应
  interface RecalculateStatsResponse {
    success: boolean;
    message: string;
    data: {
      updated_dates: string[];
      activity_count: number;
      commission_count: number;
      type: string;
    };
  }
}
