/**
 * 导航类型定义
 * 定义所有导航栈的类型参数
 */

import { NavigatorScreenParams } from '@react-navigation/native';
import type { SystemMessageResponse } from '../types/dto';
import type { Course } from '../types/schedule';

// ==================== 主Tab导航参数 ====================
export type MainTabParamList = {
  HomeTab: NavigatorScreenParams<HomeStackParamList>;
  MessageTab: NavigatorScreenParams<MessageStackParamList>;
  ScheduleTab: NavigatorScreenParams<ScheduleStackParamList>;
  ProfileTab: NavigatorScreenParams<ProfileStackParamList>;
};

// ==================== 首页Stack ====================
export type HomeStackParamList = {
  Home: undefined;
  PostDetail: { postId: string; scrollToComments?: boolean };
  Search: undefined;
  UserProfile: { userId: string };
  FollowList: { userId: string; type: 'following' | 'followers' };
};

// ==================== 消息Stack ====================
export type MessageStackParamList = {
  MessageList: undefined;
  Chat: {
    conversationId: string;
    userId?: string;
    isGroupChat?: boolean;
    groupId?: number;
    groupName?: string;
  };
  Notifications: undefined;
  CreateGroup: undefined;
  JoinGroup: undefined;
  GroupInfo: { groupId: number; conversationId?: string };
  GroupMembers: { groupId: number };
  GroupRequestDetail: { message: SystemMessageResponse };
  GroupInviteDetail: { message: SystemMessageResponse };
  PrivateChatInfo: {
    conversationId: string;
    userId: string;
    userName?: string;
    userAvatar?: string | null;
  };
};

// ==================== 个人中心Stack ====================
export type ProfileStackParamList = {
  Profile: undefined;
  Settings: undefined;
  EditProfile: undefined;
  AccountSecurity: undefined;
  MyPosts: undefined;
  Bookmarks: undefined;
  NotificationSettings: undefined;
  BlockedUsers: undefined;
};

// ==================== 课程表Stack ====================
export type ScheduleStackParamList = {
  Schedule: undefined;
  CourseDetail: { course: Course; relatedCourses: Course[] };
};

// ==================== 认证Stack ====================
export type AuthStackParamList = {
  Login: undefined;
  Register: undefined;
  ForgotPassword: undefined;
};

// ==================== 根导航 ====================
export type RootStackParamList = {
  Main: NavigatorScreenParams<MainTabParamList>;
  Auth: undefined;
  PostDetail: { postId: string; scrollToComments?: boolean };
  UserProfile: { userId: string };
  CreatePost:
    | undefined
    | {
        mode?: 'create' | 'edit';
        postId?: string;
      };
  Chat: {
    conversationId: string;
    userId?: string;
    isGroupChat?: boolean;
    groupId?: number;
    groupName?: string;
  };
  FollowList: { userId: string; type: 'following' | 'followers' };
  CreateGroup: undefined;
  JoinGroup: undefined;
  GroupInfo: { groupId: number; conversationId?: string };
  GroupMembers: { groupId: number };
  GroupRequestDetail: { message: SystemMessageResponse };
  GroupInviteDetail: { message: SystemMessageResponse };
  PrivateChatInfo: {
    conversationId: string;
    userId: string;
    userName?: string;
    userAvatar?: string | null;
  };
};

// ==================== 全局类型声明 ====================
declare global {
  namespace ReactNavigation {
    interface RootParamList extends RootStackParamList {}
  }
}

// ==================== 屏幕名称类型（用于路由）====================
export type HomeScreenNames = keyof HomeStackParamList;
export type MessageScreenNames = keyof MessageStackParamList;
export type ProfileScreenNames = keyof ProfileStackParamList;
export type MainTabScreenNames = keyof MainTabParamList;
export type RootScreenNames = keyof RootStackParamList;

// ==================== Tab 类型 ====================
export type TabName = 'HomeTab' | 'MessageTab' | 'ScheduleTab' | 'ProfileTab';

// ==================== 导航项配置 ====================
export interface NavItemConfig {
  name: TabName;
  label: string;
  icon: string;
  iconOutline: string;
}
