/**
 * 通用响应接口
 */
export interface ApiResponse<T = any> {
  code: number;
  message: string;
  data: T;
  msg?: string; // 兼容后端返回的msg字段
}

/**
 * 统一分页数据接口 (合并了 PageData 和 TableDataInfo)
 */
export interface PageData<T> {
  records?: T[]; // MyBatis Plus 风格
  rows?: T[]; // 若依框架风格
  total: number;
  size?: number;
  current?: number;
  pages?: number;
  code?: number;
  msg?: string;
}

// ==================== 通知相关 ====================

/**
 * 通知接口
 */
export interface Notification {
  notificationId: number;
  title: string;
  content: string;
  type: 'todo' | 'alert' | 'message' | 'announcement';
  priority: 'high' | 'medium' | 'low';
  read: boolean;
  readTime?: string;
  createTime: string;
  expirationDate?: string;
  actions?: string; // JSON字符串
  attachments?: string; // JSON字符串
  businessData?: string; // JSON字符串
}

/**
 * 统一查询参数接口 (可复用于各种查询场景)
 */
export interface BaseQuery {
  pageNum?: number;
  pageSize?: number;
  keyword?: string;
  startTime?: string;
  endTime?: string;
  status?: string;
  type?: string;
  [key: string]: any;
}

/**
 * 通知查询参数 (继承基础查询)
 */
export interface NotificationParams extends BaseQuery {
  isRead?: boolean;
}

/**
 * 通知统计接口
 */
export interface NotificationCountVO {
  total: number;
  todo: number;
  alert: number;
  message: number;
  announcement: number;
}


// ==================== 个人数据相关 ====================

/**
 * 趋势数据基础接口
 */
export interface TrendData {
  today: number;
  todayTrend: number;
  week: number;
  weekTrend: number;
  month: number;
  monthTrend: number;
}

/**
 * 工作量数据接口
 */
export interface WorkloadData extends TrendData {}

/**
 * 销售数据接口
 */
export interface SalesData extends TrendData {}

/**
 * 绩效数据接口
 */
export interface PerformanceData {
  rank: number;
  percentage: number;
  target: number;
}

/**
 * 统计数据接口
 */
export interface StatisticsData {
  newCustomers: number;
  policies: number;
  renewals: number;
  claims: number;
}

/**
 * 个人数据概览接口
 */
export interface PersonalData {
  workload: WorkloadData;
  sales: SalesData;
  performance: PerformanceData;
  statistics: StatisticsData;
}

// ==================== 快捷入口相关 ====================

/**
 * 快捷入口配置接口
 */
export interface ShortcutItem {
  id: string;
  label: string;
  icon: string;
  iconColor: string;
  route: string;
  menuId?: string | number;
  menuName?: string;
}

// ==================== 仪表板组件相关 ====================

/**
 * 组件宽度类型
 */
export type ComponentWidthType = 'third' | 'half' | 'two-thirds' | 'full';

/**
 * 组件分类
 */
export type ComponentCategory = 'data' | 'notification' | 'shortcut' | 'chart' | 'other';

/**
 * 可用组件定义接口
 */
export interface AvailableComponent {
  componentId: string;
  componentName: string;
  description: string;
  icon?: string;
  permission: string;
  defaultWidthType: ComponentWidthType;
  category: ComponentCategory;
  sortOrder?: number;
  isSystem?: boolean; // 是否为系统组件
}

/**
 * 用户组件配置接口
 */
export interface DashboardComponentConfig {
  configId?: number;
  userId: number;
  componentId: string;
  componentName: string;
  isEnabled: boolean;
  displayOrder: number;
  widthType: ComponentWidthType;
  createTime?: string;
  updateTime?: string;
}

/**
 * 合并后的用户组件接口
 */
export interface UserComponent extends AvailableComponent, DashboardComponentConfig {}

/**
 * 仪表板状态接口
 */
export interface DashboardState {
  availableComponents: AvailableComponent[];
  userConfigs: DashboardComponentConfig[];
  userComponents: UserComponent[];
  personalData: PersonalData | null;
  loading: boolean;
  saving: boolean;
  cacheTime: number;
  lastUpdateTime: number;
}

/**
 * 组件配置统计接口
 */
export interface ConfigSummary {
  total: number;
  enabled: number;
  disabled: number;
}

// ==================== 导出别名类型 ====================

export type {
  // 基础类型重新导出
  ComponentWidthType as WidthType,
  ComponentCategory as Category,
  NotificationParams as NotifyParams,
  DashboardComponentConfig as ComponentConfig,
  AvailableComponent as Component,
  BaseQuery as SearchParams // 使用 BaseQuery 替代 SearchParams
};
