/** 项目类型 */
export interface ProjectResp {
  projectId: string // 项目ID (API返回的是字符串)
  projectCode?: string  // 项目编号
  projectName: string  // 项目名称
  projectIntro?: string // 项目简介
  farmName: string    // 风场名称 (API字段名是farmName)
  farmAddress?: string // 风场地址 (API字段名是farmAddress)
  client?: string // 委托单位
  clientContact?: string // 委托单位联系人
  clientPhone?: string // 委托单位联系电话
  inspectionContact?: string // 检查单位联系人
  inspectionPhone?: string // 检查单位联系电话
  inspectionUnit?: string // 检查单位
  projectScale?: string // 项目规模
  scale?: string // 项目规模 (API可能使用scale字段)
  turbineModel?: string // 机组型号 (API字段名是turbineModel)
  projectCategory?: string // 项目类型/服务
  projectManagerId?: string // 项目经理ID
  projectManagerName?: string // 项目经理姓名
  projectOrigin?: string // 项目来源

  projectStaff?: string[] // 施工人员
  startDate?: string // 开始日期
  endDate?: string // 结束日期
  status: number // 状态 (API返回数字类型)
  statusLabel?: string // 状态标签 (API返回的状态文本)
  constructorIds?: string // 施工人员ID
  constructorName?: string // 施工人员姓名
  coverUrl?: string // 封面URL
  createDt?: Date
  updateDt?: Date

  // 为了保持向后兼容，添加一些别名字段
  id?: string // projectId的别名
  fieldName?: string // farmName的别名
  fieldLocation?: string // farmAddress的别名
  commissionUnit?: string // client的别名
  commissionContact?: string // clientContact的别名
  commissionPhone?: string // clientPhone的别名
  orgNumber?: string // turbineModel的别名
  projectManager?: string // projectManagerName的别名
  projectPeriod?: [string, string] // 项目周期
}

export interface ProjectQuery {
  projectName?: string
  projectCode?: string
  status?: string
  fieldName?: string
}

export interface ProjectPageQuery extends ProjectQuery, PageQuery {}

/** 任务组类型 */
export interface TaskGroupResp {
  id: number
  groupName: string
  projectId: number
  createDt?: Date
}

/** 任务类型 */
export interface TaskResp {
  id: number
  taskName: string
  taskCode: string
  projectId: number
  groupId?: number
  responsiblePerson: string
  participants: string[]
  taskPeriod: [string, string]
  superior?: number
  project?: string
  plannedHours: number
  status: string
  progress: number
  description?: string
  createDt?: Date
  updateDt?: Date
}

export interface TaskQuery {
  projectId?: number
  groupId?: number
  taskName?: string
  status?: string
}

export interface TaskPageQuery extends TaskQuery, PageQuery {}

// ==================== 人员调度相关类型 ====================

/** 项目看板统计数据 */
export interface ProjectKanbanStats {
  totalProjectsCount: string
  pendingProjectCount: string
  inProgressProjectCount: string
  completedProjectCount: string
  auditedProjectCount: string
  acceptedProjectCount: string
  totalTurbineCount: string
  pendingTurbineCount: string
  inProgressTurbineCount: string
  completedTurbineCount: string
  auditedTurbineCount: string
  acceptedTurbineCount: string
  totalTaskCount: string
  pendingTaskCount: string
  inProgressTaskCount: string
  completedTaskCount: string
  totalMemberCount: string
  projectManagerCount: string
  safetyOfficerCount: string
  qualityOfficerCount: string
  constructorCount: string
  teamLeaderCount: string
}

// ==================== 工作组相关类型 ====================

/** 工作组类型 */
export interface WorkGroup {
  id: string
  name: string
  description: string
  projectId: string
  status: 'ACTIVE' | 'INACTIVE' | 'COMPLETED'
  workTypeGroups: WorkTypeGroup[]
  memberCount: number
  requiredCount: number
  members?: WorkGroupMember[]
  createTime: string
  updateTime?: string
}

/** 工种分组类型 */
export interface WorkTypeGroup {
  id?: string
  name: string
  requiredCount: number
  priority: 'HIGH' | 'MEDIUM' | 'LOW'
  assignedCount?: number
}

/** 工作组成员类型 */
export interface WorkGroupMember {
  id: string
  name: string
  role: string
  avatar?: string
  phone?: string
  email?: string
  workTypes?: string[]
  joinTime?: string
}

/** 工作组查询参数 */
export interface WorkGroupQuery {
  projectId?: string
  name?: string
  status?: string
  workType?: string
}

/** 工作组分页查询参数 */
export interface WorkGroupPageQuery extends WorkGroupQuery, PageQuery {}

/** 创建工作组请求参数 */
export interface CreateWorkGroupReq {
  name: string
  description?: string
  projectId: string
  workTypeGroups: WorkTypeGroup[]
}

/** 更新工作组请求参数 */
export interface UpdateWorkGroupReq {
  id: string
  name?: string
  description?: string
  status?: string
  workTypeGroups?: WorkTypeGroup[]
}

/** 分配工人到工作组请求参数 */
export interface AssignWorkerReq {
  workGroupId: string
  workerIds: string[]
  workTypeName: string
}

/** 从工作组移除工人请求参数 */
export interface RemoveWorkerReq {
  workGroupId: string
  workerId: string
  workTypeName: string
}

/** 项目看板数据 */
export interface ProjectKanbanData {
  inProgressProjects: ProjectCard[]
  preparingProjects: ProjectCard[]
  ongoingProjects: ProjectCard[]
  pendingProjects: ProjectCard[]
  suspendedProjects: ProjectCard[]
  completedProjects: ProjectCard[]
  acceptanceProjects: ProjectCard[]
  collectionProjects: ProjectCard[]
  settledProjects: ProjectCard[]
}

/** 项目卡片信息 */
export interface ProjectCard {
  id: string | number
  name: string
  status: number | 'preparing' | 'ongoing' | 'pending' | 'inProgress' | 'suspended' | 'completed' | 'acceptance' | 'collection' | 'settled'
  budget: number
  manager: string
  teamSize: number
  preparationProgress?: number
  progress?: number
  startDate?: string
  endDate?: string
  plannedStartDate?: string
  alerts?: ProjectAlert[]
  teamMembers: TeamMemberResp[]
  requirements: ProjectRequirementResp[]
  farmName?: string
  scale?: string
  createTime?: string
}

/** 项目异常信息 */
export interface ProjectAlert {
  type: 'cost' | 'personnel' | 'schedule' | 'quality'
  message: string
}

/** 项目详情响应 */
export interface ProjectDetailResp extends ProjectCard {
  // 继承ProjectCard的所有字段，可以添加更多详情字段
}

/** 团队成员响应 */
export interface TeamMemberResp {
  id: string | number
  name: string
  roleType: string
  phone?: string
  email?: string
  avatar?: string
  joinDate?: string
  performance?: number
  remark?: string
  status?: 'ACTIVE' | 'SUSPENDED' | 'INACTIVE'
}

/** 后端返回的团队成员数据结构 */
export interface BackendTeamMemberResp {
  memberId: string
  projectId: string
  projectName: string
  turbineId: string | null
  turbineName: string | null
  taskGroupId: string | null
  taskGroupName: string | null
  taskId: string | null
  taskName: string | null
  userId: string
  name: string
  phone: string | null
  email: string | null
  position: string
  status: 'ACTIVE' | 'SUSPENDED' | 'INACTIVE'
  skills: string
  joinDate: string
  remark: string
  userAccount: string
  userAvatar: string | null
  roleType: string
  roleTypeDesc: string
  jobCode: string
  jobCodeDesc: string
  jobDesc: string
  leaveDate: string | null
  statusDesc: string
}

/** 团队成员查询参数（支持筛选、分页、搜索） */
export interface TeamMemberQuery extends PageQuery {
  projectId: string | number
  name?: string // 姓名搜索
  position?: string // 项目岗位筛选
  status?: string // 状态筛选
  joinDateStart?: string // 入职日期开始
  joinDateEnd?: string // 入职日期结束
  sortBy?: 'name' | 'roleType' | 'joinDate' | 'status' // 排序字段
  sortOrder?: 'asc' | 'desc' // 排序方向
}

/** 团队成员导出查询参数（不包含分页） */
export interface TeamMemberExportQuery {
  projectId: string | number
  name?: string // 姓名搜索
  position?: string // 项目岗位筛选
  status?: string // 状态筛选
  joinDateStart?: string // 入职日期开始
  joinDateEnd?: string // 入职日期结束
  sortBy?: 'name' | 'roleType' | 'joinDate' | 'status' // 排序字段
  sortOrder?: 'asc' | 'desc' // 排序方向
}

/** 创建团队成员表单 */
export interface CreateTeamMemberForm {
  projectId: string | number
  roleType: string // 项目岗位
  name: string
  phone: string
  email?: string
  status?: 'ACTIVE' | 'SUSPENDED' | 'INACTIVE'
  joinDate?: string
  remark?: string
}

/** 更新团队成员表单 */
export interface UpdateTeamMemberForm {
  roleType?: string // 项目岗位
  name?: string
  phone?: string
  email?: string
  status?: 'ACTIVE' | 'SUSPENDED' | 'INACTIVE'
  joinDate?: string
  remark?: string
}



/** 批量操作表单 */
export interface BatchOperationForm {
  ids: (string | number)[]
  operation: 'delete' | 'updateStatus'
  status?: 'ACTIVE' | 'SUSPENDED' | 'INACTIVE'
}

/** 导入结果响应 */
export interface ImportResultResp {
  success: boolean
  totalCount: number
  successCount: number
  failCount: number
  errors?: Array<{
    row: number
    message: string
  }>
}

/** 人员需求响应 */
export interface PersonnelRequirementResp {
  id: string | number
  title: string
  type: 'personnel' | 'equipment'
  position?: string
  equipmentType?: string
  count: number
  skills: string[]
  description?: string
  priority: 'low' | 'medium' | 'high'
  status: 'pending' | 'recruiting' | 'completed'
  createTime: string
  updateTime: string
}

/** 创建需求表单 */
export interface CreateRequirementForm {
  projectId: string | number
  type: 'personnel' | 'equipment'
  position?: string
  equipmentType?: string
  count: number
  skills: string[]
  description?: string
  priority: 'low' | 'medium' | 'high'
}

/** 简化项目需求响应类型 */
export interface ProjectRequirementResp {
  id: string | number
  title: string
  description: string
  priority: 'low' | 'medium' | 'high'
  status: 'pending' | 'recruiting' | 'completed'
  createTime: string
  updateTime: string
}

/** 简化创建项目需求表单类型 */
export interface CreateProjectRequirementForm {
  projectId: string | number
  description: string
  priority: 'low' | 'medium' | 'high'
}

/** 更新需求状态表单 */
export interface UpdateRequirementStatusForm {
  requirementId: string | number
  status: 'pending' | 'recruiting' | 'completed'
}

// ==================== 人员组织相关类型 ====================

/** 工种响应 */
export interface WorkTypeResp {
  id: string | number
  name: string
  code: string
  description?: string
  requiredCertifications?: string[]
  sort?: number
}

/** 施工人员响应 */
export interface ConstructorResp {
  id: string | number
  name: string
  phone: string
  email?: string
  avatar?: string
  workTypes: string[] // 工种列表
  certifications: CertificationResp[]
  experience: number // 工作经验（年）
  status: 'ACTIVE' | 'INACTIVE' | 'BUSY'
  rating: number // 评分
  joinDate: string
  remark?: string
}

/** 证书响应 */
export interface CertificationResp {
  id: string | number
  name: string
  type: string
  code: string
  issueDate: string
  expiryDate: string
  issuingAuthority: string
  status: 'VALID' | 'EXPIRED' | 'EXPIRING_SOON'
  imageUrl?: string
}

/** 施工人员查询参数 */
export interface ConstructorQuery extends PageQuery {
  name?: string
  workType?: string
  status?: string
  hasCertification?: boolean
  experienceMin?: number
  experienceMax?: number
}

/** 人员组织响应 */
export interface PersonnelOrganizationResp {
  projectId: string | number
  projectName: string
  workTypeAssignments: WorkTypeAssignmentResp[]
  totalPersonnel: number
  assignedPersonnel: number
  availablePersonnel: number
}

/** 工种分配响应 */
export interface WorkTypeAssignmentResp {
  workTypeId: string | number
  workTypeName: string
  workTypeCode: string
  requiredCount: number
  assignedCount: number
  constructors: ConstructorAssignmentResp[]
}

/** 施工人员分配响应 */
export interface ConstructorAssignmentResp {
  constructorId: string | number
  constructorName: string
  phone: string
  avatar?: string
  workTypes: string[]
  certifications: CertificationResp[]
  experience: number
  rating: number
  assignmentDate: string
  status: 'ASSIGNED' | 'WORKING' | 'COMPLETED'
  remark?: string
}

/** 分配施工人员请求 */
export interface AssignConstructorReq {
  projectId: string | number
  workTypeId: string | number
  constructorIds: (string | number)[]
  assignmentDate?: string
  remark?: string
}

/** 移除施工人员请求 */
export interface RemoveConstructorReq {
  projectId: string | number
  constructorIds: (string | number)[]
  reason?: string
}

/** 更新分配信息请求 */
export interface UpdateAssignmentReq {
  projectId: string | number
  constructorId: string | number
  workTypeId?: string | number
  status?: string
  remark?: string
}

/** 人员统计响应 */
export interface PersonnelStatsResp {
  totalPersonnel: number
  assignedPersonnel: number
  availablePersonnel: number
  workTypeStats: {
    workTypeName: string
    requiredCount: number
    assignedCount: number
    shortageCount: number
  }[]
  certificationStats: {
    certificationType: string
    count: number
  }[]
  experienceStats: {
    range: string
    count: number
  }[]
}

/** 分页查询基础参数 */
export interface PageQuery {
  page: number
  pageSize: number
}

/** 分页响应 */
export interface PageRes<T> {
  list: T[]
  total: number
  page: number
  pageSize: number
}

// ==================== 工作组相关类型 ====================

/** 工作组类型 */
export interface WorkGroup {
  id: string
  name: string
  description: string
  projectId: string
  status: 'ACTIVE' | 'INACTIVE' | 'COMPLETED'
  workTypeGroups: WorkTypeGroup[]
  memberCount: number
  requiredCount: number
  members?: WorkGroupMember[]
  createTime: string
  updateTime?: string
}

/** 工种分组类型 */
export interface WorkTypeGroup {
  id?: string
  name: string
  requiredCount: number
  priority: 'HIGH' | 'MEDIUM' | 'LOW'
  assignedCount?: number
}

/** 工作组成员类型 */
export interface WorkGroupMember {
  id: string
  name: string
  role: string
  avatar?: string
  phone?: string
  email?: string
  workTypes?: string[]
  joinTime?: string
}

/** 工作组查询参数 */
export interface WorkGroupQuery {
  projectId?: string
  name?: string
  status?: string
  workType?: string
}

/** 工作组分页查询参数 */
export interface WorkGroupPageQuery extends WorkGroupQuery, PageQuery {}

/** 创建工作组请求参数 */
export interface CreateWorkGroupReq {
  name: string
  description?: string
  projectId: string
  workTypeGroups: WorkTypeGroup[]
}

/** 更新工作组请求参数 */
export interface UpdateWorkGroupReq {
  id: string
  name?: string
  description?: string
  status?: string
  workTypeGroups?: WorkTypeGroup[]
}

/** 分配工人到工作组请求参数 */
export interface AssignWorkerReq {
  workGroupId: string
  workerIds: string[]
  workTypeName: string
}

/** 从工作组移除工人请求参数 */
export interface RemoveWorkerReq {
  workGroupId: string
  workerId: string
  workTypeName: string
}

// 扩展项目类型，包含工作组信息
export interface ProjectWithWorkGroups extends ProjectResp {
  workGroups?: WorkGroup[]
}