/**
 * 通用用户信息类型, 反映了JWT中包含的声明
 */
export interface User {
  id: number;
  name: string;
  email: string;
  role: string;
  phone?: string;
  status?: string;
  region?: string;
  skills?: string[];
  gridX?: number;
  gridY?: number;
}

/**
 * 用户登录请求体
 */
export interface LoginRequest {
  email: string;
  password: string;
}

/**
 * 登录成功响应体, 与后端完全匹配
 */
export interface LoginResponse {
  accessToken: string;
}

/**
 * 用户注册请求体
 */
export interface SignUpRequest {
  name: string;
  email: string;
  phone: string;
  password: string;
  verificationCode: string;
  role: string;
}

/**
 * 使用验证码重置密码请求体, 对应后端的 PasswordResetWithCodeDto
 */
export interface ResetPasswordWithCodeRequest {
  email: string;
  code: string;
  newPassword: string;
}

/**
 * 分页请求参数
 */
export interface Pageable {
  page?: number;
  size?: number;
  sort?: string;
}

/**
 * 分页响应体
 */
export interface Page<T> {
  content: T[];
  totalPages: number;
  totalElements: number;
  size: number;
  number: number;
}

/**
 * 后端 UserAccount 实体类的完整映射
 */
export interface UserAccount {
  id: number;
  name: string;
  email: string;
  phone: string;
  role: string;
  status: string;
  gender?: string;
  region?: string;
  gridX?: number;
  gridY?: number;
  level?: string;
  skills?: string[];
  currentLatitude?: number;
  currentLongitude?: number;
  createdAt: string; // Assuming ISO date string
  updatedAt: string; // Assuming ISO date string
}

/**
 * 用户更新请求体, 对应后端的 UserUpdateRequest
 */
export interface UserUpdateRequest {
  name?: string;
  phone?: string;
  region?: string;
  role?: string;
  status?: string;
  gender?: 'MALE' | 'FEMALE' | 'OTHER';
  gridX?: number;
  gridY?: number;
  level?: string;
  skills?: string[];
  currentLatitude?: number;
  currentLongitude?: number;
}

// --- Dashboard DTOs ---

/**
 * Key statistics for the main dashboard.
 * @param totalFeedbacks - Total number of feedbacks.
 * @param confirmedFeedbacks - Number of confirmed feedbacks.
 * @param totalAqiRecords - Total number of AQI records.
 * @param activeGridWorkers - Number of active grid workers.
 */
export type DashboardStatsDTO = {
  totalFeedbacks: number;
  confirmedFeedbacks: number;
  totalAqiRecords: number;
  activeGridWorkers: number;
};

/**
 * Data for AQI level distribution chart.
 * @param level - The AQI descriptive level (e.g., "Good", "Moderate").
 * @param count - The number of monitoring points at this level.
 */
export type AqiDistributionDTO = {
  level: string;
  count: number;
};

/**
 * A single data point for a time-series trend chart.
 * @param yearMonth - The date for the data point in "YYYY-MM" format.
 * @param count - The value for that date (e.g., number of exceedances).
 */
export type TrendDataPointDTO = {
  yearMonth: string;
  count: number;
};

/**
 * Grid coverage statistics for a specific city.
 * @param city - The name of the city.
 * @param totalGrids - The total number of grids in the city.
 * @param coveredGrids - The number of grids with assigned personnel.
 * @param coverageRate - The calculated coverage percentage.
 */
export type GridCoverageDTO = {
  city: string;
  totalGrids: number;
  coveredGrids: number;
  coverageRate: number;
};

/**
 * A single point for a heatmap visualization.
 * @param lat - Latitude of the data point.
 * @param lng - Longitude of the data point.
 * @param value - The intensity value for the heatmap.
 */
export type HeatmapPointDTO = {
  lat: number;
  lng: number;
  value: number;
};

/**
 * Detailed statistics for a specific pollutant.
 * @param pollutantName - The name of the pollutant (e.g., "PM2.5").
 * @param averageValue - The average value over a period.
 * @param maxValue - The maximum recorded value.
 * @param unit - The measurement unit (e.g., "µg/m³").
 */
export type PollutionStatsDTO = {
  pollutantName: string;
  averageValue: number;
  maxValue: number;
  unit: string;
};

/**
 * Statistics on task completion status.
 * @param totalTasks - Total number of tasks.
 * @param completedTasks - Number of completed tasks.
 * @param completionRate - Completion rate of tasks.
 */
export type TaskStatsDTO = {
  totalTasks: number;
  completedTasks: number;
  completionRate: number;
};

/**
 * A single point for the AQI heatmap, including pollutant info.
 * Extends HeatmapPointDTO with additional details.
 */
export type AqiHeatmapPointDTO = HeatmapPointDTO & {
  primaryPollutant: string;
  aqi: number;
};

/**
 * 污染物类型枚举
 */
export enum PollutionType {
  PM25 = 'PM25',
  O3 = 'O3',
  NO2 = 'NO2',
  SO2 = 'SO2',
  OTHER = 'OTHER'
}

/**
 * 污染物阈值设置
 * @param pollutionType - 污染物类型
 * @param pollutantName - 污染物名称
 * @param threshold - 阈值
 * @param unit - 单位
 * @param description - 描述
 */
export type PollutantThresholdDTO = {
  pollutionType: PollutionType;
  pollutantName: string;
  threshold: number;
  unit: string;
  description?: string;
};

/**
 * Represents a geographical grid cell.
 * Matches the backend Grid entity.
 */
export interface Grid {
  id: number;
  gridX: number;
  gridY: number;
  cityName: string;
  districtName?: string;
  description?: string;
  isObstacle: boolean;
}

// ... 您可以根据API文档继续添加其他类型定义 

// --- Task and Assignment DTOs ---

export interface AssigneeInfoDTO {
  id: number;
  name: string;
  phone: string;
}

export interface UserInfoDTO {
  id: number;
  name: string;
  phone: string;
  email: string;
  role?: string;
}

export interface TaskInfoDTO {
  id: number;
  status: string; // Should match TaskStatus enum from backend
  assignee: AssigneeInfoDTO;
  submissionInfo: SubmissionInfoDTO | null;
}

export interface AttachmentDTO {
  id: number;
  fileName: string;
  fileType: string;
  url: string;
  uploadedAt: string; // ISO date string
}

export interface SubmissionInfoDTO {
  comments: string;
  attachments: AttachmentDTO[];
}

/**
 * 操作日志类型
 */
export interface OperationLog {
  id: number;
  userId: number;
  userName: string;
  operationType: string;
  operationTypeDesc: string;
  description: string;
  targetId: string;
  targetType: string;
  ipAddress: string;
  createdAt: string;
}

/**
 * Task Summary DTO for supervisor view.
 * This should match `TaskSummaryDTO` from the backend.
 */
