import request from '@/config/axios'

export interface ProjectOverviewExportReqVO {
  year?: number
  officeId?: number
  sortType?: string
}

export interface ProjectOverviewPreviewRespVO {
  year?: number
  officeName?: string
  employeeColumns?: ProjectOverviewEmployeeColumn[]
  rows?: ProjectOverviewProjectRow[]
  totalRow?: ProjectOverviewProjectRow
}

export interface ProjectOverviewEmployeeColumn {
  employeeId?: number
  employeeName?: string
}

export interface ProjectOverviewProjectRow {
  serialNo?: number
  totalRow?: boolean
  projectName?: string
  progressText?: string
  workStage?: string
  totalOutputAmountWan?: number
  historicalIssuedRatio?: number
  currentSettlementRatio?: number
  currentSettlementAmountWan?: number
  pendingRatio?: number
  employeeAmountMap?: Record<string, ProjectOverviewEmployeeAmountValue>
}

export interface ProjectOverviewEmployeeAmountValue {
  quarterOneAmountWan?: number
  quarterTwoAmountWan?: number
  quarterThreeAmountWan?: number
  quarterFourAmountWan?: number
  annualTotalAmountWan?: number
}

export interface EmployeeOutputSummaryExportReqVO {
  year?: number
  officeId?: number
  employeeId?: number
  employeeStatus?: string
  sortType?: string
}

export interface EmployeeOutputSummaryPreviewRespVO {
  year?: number
  kValue?: number
  rows?: EmployeeOutputSummaryRow[]
  totalRow?: EmployeeOutputSummaryRow
}

export interface EmployeeOutputSummaryRow {
  serialNo?: number
  employeeName?: string
  officeName?: string
  quarterOneAmount?: number
  quarterTwoAmount?: number
  quarterThreeAmount?: number
  quarterFourAmount?: number
  annualTotalAmount?: number
  officeLeaderOrBimAmount?: number
  totalAssessmentOutputAmount?: number
  expectedCostAmount?: number
  basicAssessmentOutputAmount?: number
  remainingOutputAmount?: number
  estimatedYearEndPerformanceAmount?: number
  totalRow?: boolean
}

export interface ProjectBudgetExportReqVO {
  projectId: number
  year?: number
}

export interface ProjectBudgetPreviewRespVO {
  year?: number
  projectCode?: string
  projectName?: string
  remark?: string
  budgetRows?: ProjectBudgetPreviewBudgetRow[]
  quarterBudgetRows?: ProjectBudgetPreviewQuarterRow[]
}

export interface ProjectBudgetPreviewBudgetRow {
  rowType?: string
  planningId?: number
  planningContent?: string
  displayDesignPart?: string
  displayBuildingType?: string
  internalGuidanceUnitPrice?: number
  designArea?: number
  buildingOrUnitCount?: number
  drawingSetFactor?: number
  scaleFactor?: number
  modificationFactor?: number
  complexityFactor?: number
  subtotalArea?: number
  currentDesignStageRatio?: number
  assessmentOutputValueWan?: number
}

export interface ProjectBudgetPreviewQuarterRow {
  serialNo?: number
  totalRow?: boolean
  outputType?: string
  designContent?: string
  budgetYear?: number
  totalDesignArea?: number
  totalAssessmentArea?: number
  totalAssessmentOutputWan?: number
  designStageRatio?: number
  designStageOutputWan?: number
  historicalIssuedRatio?: number
  quarterOneRatio?: number
  quarterTwoRatio?: number
  quarterThreeRatio?: number
  quarterFourRatio?: number
  currentYearRatio?: number
  pendingRatio?: number
  quarterOneAmountWan?: number
  quarterTwoAmountWan?: number
  quarterThreeAmountWan?: number
  quarterFourAmountWan?: number
  yearTotalAmountWan?: number
  ratioRemark?: string
}

export interface ProjectQuarterOutputExportReqVO {
  planningId: number
  year?: number
}

export interface ProjectLeadQuarterOutputExportReqVO {
  planningId: number
  year?: number
}

export interface SpecialtyPersonOutputExportReqVO {
  planningId: number
  specialtyCode: string
  year?: number
}

export interface SpecialtyPersonOutputPreviewReqVO {
  planningId: number
  year?: number
}

export interface SpecialtyPersonOutputPreviewRespVO {
  planningId: number
  year: number
  projectName?: string
  groups?: SpecialtyPersonOutputPreviewGroupRow[]
}

export interface SpecialtyPersonOutputPreviewGroupRow {
  specialtyCode: string
  specialtyName?: string
  exportable?: boolean
  specialtyAmount?: number
  roleTotal?: number
  personCount?: number
  overRatio?: boolean
  specialtyQuarterOneAmountWan?: number
  specialtyQuarterTwoAmountWan?: number
  specialtyQuarterThreeAmountWan?: number
  specialtyQuarterFourAmountWan?: number
  specialtyYearTotalAmountWan?: number
  rows: SpecialtyPersonOutputPreviewRoleRow[]
}

export interface SpecialtyPersonOutputPreviewRoleRow {
  specialtyCode: string
  specialtyName?: string
  roleCode: string
  roleName?: string
  roleRatio?: number
  roleAmount?: number
  personTotalRatio?: number
  persons: SpecialtyPersonOutputPreviewPersonRow[]
}

export interface SpecialtyPersonOutputPreviewPersonRow {
  personKey: string
  employeeId?: number
  employeeName?: string
  personRatio?: number
  personAmount?: number
  roleNames?: string
  adjustedPersonRatio?: number
  quarterOneRatio?: number
  quarterOneAmountWan?: number
  quarterTwoRatio?: number
  quarterTwoAmountWan?: number
  quarterThreeRatio?: number
  quarterThreeAmountWan?: number
  quarterFourRatio?: number
  quarterFourAmountWan?: number
  yearTotalRatio?: number
  yearTotalAmountWan?: number
}

export const exportProjectBudget = (params: ProjectBudgetExportReqVO) => {
  return request.download({ url: '/tjt/report/project-budget/export-excel', params })
}

export const getProjectBudgetPreview = (params: ProjectBudgetExportReqVO) => {
  return request.get<ProjectBudgetPreviewRespVO>({
    url: '/tjt/report/project-budget/preview',
    params: { ...params, _t: Date.now() }
  })
}

export const exportProjectQuarterOutput = (params: ProjectQuarterOutputExportReqVO) => {
  return request.download({
    url: '/tjt/report/project-quarter-output/export-excel',
    params
  })
}

export const exportProjectLeadQuarterOutput = (params: ProjectLeadQuarterOutputExportReqVO) => {
  return request.download({
    url: '/tjt/report/project-lead-quarter-output/export-excel',
    params
  })
}

export const exportSpecialtyPersonOutput = (params: SpecialtyPersonOutputExportReqVO) => {
  return request.download({ url: '/tjt/report/specialty-person-output/export-excel', params })
}

export const getSpecialtyPersonOutputPreview = (params: SpecialtyPersonOutputPreviewReqVO) => {
  return request.get({ url: '/tjt/report/specialty-person-output/preview', params })
}

export const exportProjectOverview = (params: ProjectOverviewExportReqVO) => {
  return request.download({ url: '/tjt/report/project-overview/export-excel', params })
}

export const getProjectOverviewPreview = (params: ProjectOverviewExportReqVO) => {
  return request.get<ProjectOverviewPreviewRespVO>({
    url: '/tjt/report/project-overview/preview',
    params: { ...params, _t: Date.now() }
  })
}

export const exportEmployeeOutputSummary = (params: EmployeeOutputSummaryExportReqVO) => {
  return request.download({ url: '/tjt/report/employee-output-summary/export-excel', params })
}

export const getEmployeeOutputSummaryPreview = (params: EmployeeOutputSummaryExportReqVO) => {
  return request.get<EmployeeOutputSummaryPreviewRespVO>({
    url: '/tjt/report/employee-output-summary/preview',
    params: { ...params, _t: Date.now() }
  })
}
