import { get, post, put, del } from './request'
import type {
  CooperationType,
  FacilityType,
  PageResult,
  PaymentMethod,
  Project,
  ProjectStatus
} from '../types'

/** 提交给后台的项目字段（对齐 BizProject，facilityTypes/servicePoints/locationContacts 为 JSON 字符串） */
export interface ProjectParams {
  projectName: string
  cooperationType: CooperationType
  contractId?: number | string
  customerId?: number | string
  customerName?: string
  customerPhone?: string
  contractNo?: string
  facilityTypes?: string
  industry?: string
  contractAmount?: number
  serviceStartDate?: string
  serviceEndDate?: string
  projectDescription?: string
  servicePoints?: string
  locationContacts?: string
  address?: string
  province?: string
  city?: string
  district?: string
  street?: string
  detailAddress?: string
  latitude?: string
  longitude?: string
  primaryContactName?: string
  primaryContactPhone?: string
  paymentMethod?: PaymentMethod
  contractStatus?: string
  status?: ProjectStatus
  remark?: string
}

export function getProjectList(pageNum = 1, pageSize = 10) {
  return get<PageResult<Project>>('/project/list', { pageNum, pageSize })
}

export function getProjectDetail(projectId: number | string) {
  return get<Project>(`/project/${projectId}`)
}

export function createProject(data: ProjectParams) {
  return post<number>('/project', data)
}

export function updateProject(data: ProjectParams & { projectId: number | string }) {
  return put<void>('/project', data)
}

export function deleteProject(projectId: number | string) {
  return del<void>(`/project/${projectId}`)
}
