import type { FileItem } from '@/components/UploadFiles/types.ts';

export interface ImageItem {
  url: string;
  name?: string;
  size?: number;
  file?: File;
}

export interface DisposalManagementListQuery {
  reporterId?: number;
  fixerId?: number;
}

export interface LossReportReportTaskQuery {
  taskStage?: string | null;
}

export interface DisposalManagementTableQuery extends DisposalManagementListQuery, LossReportReportTaskQuery {
  handleTaskIds: number[];
  reportDeptIds?: number[] | null;
  status?: string | null;
}

export interface LossRecordTableQuery {
  handleTaskIds: number[];
  handleDeptIds?: number[] | null;
  fixStatus?: string | null;
  isLoss?: number;
  fixerId?: number;
  reporterId?: number;
}

interface BasicResponse {
  deptName: string;
  taskStage: number;
  dueCompleteTime: string;
}

export interface DisposalManagementListResponse {
  id: number;
  handleTaskId: number;
  taskName: string;
  createdAt: string;
  updatedAt: string;
  dueCompleteTime: string;
  deptId: number;
  disasterAssessMaterials: string; // 灾后评估材料
  disasterReconstructMaterials: string; // 灾后重建材料
}

export interface UpdateDisasterHandleTaskQuery {
  id?: number;
  taskName?: string;
  disasterAssessMaterials?: string; // 灾后评估材料
  disasterReconstructMaterials?: string; // 灾后重建材料
  createdAt?: string;
  updatedAt?: string;
  isDeleted?: number;
}

export interface DisposalManagementCollapseListResponse<T> extends DisposalManagementListResponse {
  tableData: T[];
}

export interface disasterReportTaskInfoListResponse extends BasicResponse {
  id: number;
  status: number;
  reportPrincipalInfoList: { reportPrincipalId: number; reportPrincipalName: string; reportPrincipalStaffNo: string }[];
  userGroupList: string;
}

export interface disasterReportRecordDetailListResponse {
  id: number;
  buildingNo: string;
  floorNo: string;
  roomNo: string;
  affectedItems: string;
  updatedAt: string;
  responsibleDeptName: string;
  priority: string;
  fixStatus: number;
  isLoss: number;
  userGroupList: string;
  createdBy: string;
  images: string;
  fixerList: string;
  isFixPrincipal: boolean; //是否整改责任人
  safetyLevel: string;
  isAffectWork: number | null;
  estimatedLoss: string | null;
  description: string;
  remark: string;
  fixTaskId: number;
  responsibleDeptId: number;
}

export interface DisposalManagementTableResponse {
  handleTaskId: number;
  disasterReportTaskInfoList: disasterReportTaskInfoListResponse[];
}

export interface LossRecordTableResponse {
  handleTaskId: number;
  disasterReportRecordDetailList: disasterReportRecordDetailListResponse[];
}

export interface LossReportReportTaskResponse extends BasicResponse {
  id: number;
  handleTaskId: number;
  taskName: string;
  isReportPrincipal: boolean; //是否上报责任人
  updatedAt: string;
  reporterList: string; //上报责任人列表
  deptId: number;
}

export interface DisposalManagementCreateQuery {
  taskName: string;
  deptIds: number[];
  dueCompleteTime: string;
  reportRequirement: string;
  userGroupList: number[];
  isPush: boolean;
}

export interface DisposalManagementEditQuery {
  dueCompleteTime?: string;
  reportRequirement?: string;
  taskStage?: number;
  isPush?: number;
  status?: number;
  userGroupList?: number[];
}

export interface DisasterReportCreateQuery extends DisposalManagementCreateQuery {
  handleTaskId: number;
}

export interface DisasterReportEditQuery extends DisposalManagementEditQuery {
  id: number; //灾害处置上报任务id
  handleTaskId: number; //灾害处置任务id
}

export interface DisposalManagementRuleForm extends Omit<DisposalManagementCreateQuery, 'isPush'> {
  isPush: boolean | null;
  createdByName: string;
}

export interface DisposalManagementRuleFormEdit extends Omit<DisposalManagementCreateQuery, 'isPush' | 'deptIds'> {
  createdByName: string;
  deptName: string;
  isPush: number | null;
}

export interface LossReportItemFormData
  extends Omit<
    disasterReportRecordDetailListResponse,
    | 'id'
    | 'updatedAt'
    | 'responsibleDeptName'
    | 'fixStatus'
    | 'userGroupList'
    | 'images'
    | 'fixerList'
    | 'isFixPrincipal'
    | 'fixTaskId'
    | 'responsibleDeptId'
  > {
  reportTaskName: string;
  responsibleDeptId: number | null;
  userGroupList: number[];
  isPush: number;
  affectedRoom: string; //自己创造的一个数值，不要传给后端
  images: string[];
  uploadImages: File[];
}

export interface LossRecordFormData {
  reportTaskName: string;
  isLoss: number;
  buildingNo?: string;
  floorNo?: string;
  roomNo?: string;
  affectedItems?: string;
  images?: string[];
  description?: string;
  safetyLevel?: string;
  isAffectWork?: number;
  estimatedLoss?: string;
  priority?: string;
  responsibleDeptId?: number;
  remark?: string;
  userGroupList?: number[];
  isPush?: number;
  uploadImages?: File[];
}

export interface LossRecordCreateQuery extends Omit<LossRecordFormData, 'images'> {
  reportTaskId: number;
  images?: string[];
}

export interface LossRecordEditQuery extends Omit<LossRecordCreateQuery, 'reportTaskId'> {
  id: number;
}

export interface DisposalRectificationFormData {
  id?: number;
  fixStatus: string;
  fixMethod: string;
  fixDeadline: string;
  fixImages: string;
  fixMaterials: string;
  remark: string;
  createdBy: number | null;
  createdByName: string;
  uploadImages: File[];
  uploadFiles: FileItem[];
  createdAt?: string;
}

export interface DisposalRectificationCreateQuery extends DisposalRectificationFormData {
  fixTaskId: number;
}

export interface DisasterLossDetailQuery {
  handleTaskId: number;
  userIdByLossFix?: number;
  reportDeptId?: number;
}

export interface LossRecordListDetail {
  id: number;
  fixTaskId: number;
  affectedItems: string;
  buildingNo?: string;
  floorNo?: string;
  roomNo?: string;
  createdBy: number;
  updatedAt: string;
  safetyLevel: string;
  isAffectWork: number;
  estimatedLoss: string | null;
  description: string;
  images: string;
  remark: string;
  isLoss: number;
  responsibleDeptName: string;
  fixPrincipals: string;
  priority: string;
  fixRecordList: DisposalRectificationFormData[];
}

export interface ReportTaskListDetail {
  fixFinishCount: number;
  lossRecordCount: number;
  reportDeptId: number;
  reportDeptName: string;
  reportTaskId: number;
  lossRecordList: LossRecordListDetail[]; // 损失记录列表
  reportTime: string; //上报时间
}

export interface OverviewLossRecordInfo {
  needToReportDeptCount?: number; // 需上报单位数量
  reportedDeptCount?: number; // 已上报单位数量
  waitToReportDeptCount?: number; // 待上报单位数量
  overdueReportedDeptCount?: number; // 超期未上报单位数量
  lossRecordCount?: number; // 损失记录数量
  fixedLossCount?: number; // 已整改损失数量
  fixingLossCount?: number; //	整改中损失数量
  waitToFixLossCount?: number; // 待整改损失数量
}

export interface DisasterLossDetailResponse extends OverviewLossRecordInfo {
  handleTaskName: string;
  reportTaskList: ReportTaskListDetail[]; // 上报任务列表
}
