import { get, post, put, del } from './request'
import type { Contract, ContractStatus, PageResult, PaymentMethod } from '../types'

export interface ContractParams {
  contractNo: string
  contractName?: string
  customerId: number | string
  customerName?: string
  projectId?: number | string
  contractAmount: number
  paymentMethod: PaymentMethod
  signDate?: string
  servicePeriod?: string
  status?: ContractStatus
  remark?: string
}

export interface ContractListQuery {
  keyword?: string
  status?: ContractStatus
}

export function getContractList(pageNum = 1, pageSize = 10, query: ContractListQuery = {}) {
  return get<PageResult<Contract>>('/contract/list', { pageNum, pageSize, ...query })
}

export function getContractDetail(id: number | string) {
  return get<Contract>(`/contract/${id}`)
}

export function createContract(data: ContractParams) {
  return post<number>('/contract', data)
}

export function updateContract(data: ContractParams & { id: number | string }) {
  return put<void>('/contract', data)
}

export function deleteContract(id: number | string) {
  return del<void>(`/contract/${id}`)
}
