import request from '@/config/axios'

export interface ProjectRolePersonVO {
  id?: number
  projectId?: number
  roleCode: 'project_manager' | 'engineering_principal'
  roleName?: string
  employeeId?: number
  employeeName?: string
  sortNo?: number
}

export interface ProjectVO {
  id?: number
  projectName: string
  contractSignedFlag: boolean
  contractAmount?: number
  totalConstructionArea?: number
  constructionUnitName?: string
  contactName?: string
  contactPhone?: string
  contractSigningDate?: string
  projectManagerName?: string
  engineeringPrincipalName?: string
  projectType?: string
  projectCategory?: string
  projectStartYear?: number
  projectStatus?: string
  archiveFlag?: boolean
  archiveTime?: string
  pauseReason?: string
  terminateReason?: string
  finalSettlementAmount?: number
  innovationOutputRate?: number
  otherCost?: number
  rolePersons?: ProjectRolePersonVO[]
  createTime?: string
}

export type ProjectSaveVO = Omit<
  ProjectVO,
  'createTime' | 'archiveTime' | 'projectManagerName' | 'engineeringPrincipalName'
>

export interface ProjectPageReqVO extends PageParam {
  projectName?: string
  contractSignedFlag?: boolean
  projectStartYear?: number
  projectStatus?: string
  createTime?: string[]
}

export const getProjectPage = (params: ProjectPageReqVO) => {
  return request.get({ url: '/tjt/project/page', params })
}

export const getProject = (id: number) => {
  return request.get({ url: '/tjt/project/get', params: { id } })
}

export const createProject = (data: ProjectSaveVO) => {
  return request.post({ url: '/tjt/project/create', data })
}

export const updateProject = (data: ProjectSaveVO) => {
  return request.put({ url: '/tjt/project/update', data })
}

export const deleteProject = (id: number) => {
  return request.delete({ url: '/tjt/project/delete', params: { id } })
}

export const deleteProjectList = (ids: number[]) => {
  return request.delete({ url: '/tjt/project/delete-list', params: { ids: ids.join(',') } })
}
