import request from '@/config/axios'
import type { ProjectPlanningVO } from '@/api/tjt/planning'
import type { ProjectPlanningGuideDetailVO } from '@/api/tjt/planningGuideDetail'

export interface ProjectPlanningQuarterVO {
  id?: number
  planningId: number
  guideDetailId?: number
  guideDetailSortNo?: number
  distributionYear: number
  quarterNo: number
  distributionRatio?: number
  distributionAmount?: number
  createTime?: string
}

export type ProjectPlanningQuarterSaveVO = Omit<
  ProjectPlanningQuarterVO,
  'distributionAmount' | 'createTime'
>

export interface ProjectPlanningQuarterPlanningDetailVO {
  planning: ProjectPlanningVO
  quarters: ProjectPlanningQuarterVO[]
  guideDetailMode?: boolean
  historyParentMode?: boolean
  message?: string
  parentQuarters?: ProjectPlanningQuarterVO[]
  guideDetails?: ProjectPlanningQuarterGuideDetailVO[]
}

export interface ProjectPlanningQuarterGuideDetailVO extends ProjectPlanningGuideDetailVO {
  allocatedAmount?: number
  pendingAmount?: number
  quarters: ProjectPlanningQuarterVO[]
}

export const getProjectPlanningQuarter = (id: number) => {
  return request.get({ url: '/tjt/planning-quarter/get', params: { id } })
}

export const getProjectPlanningQuarterListByPlanningId = (planningId: number) => {
  return request.get({ url: '/tjt/planning-quarter/list-by-planning', params: { planningId } })
}

export const getProjectPlanningQuarterPlanningDetail = (planningId: number) => {
  return request.get({
    url: '/tjt/planning-quarter/planning-detail',
    params: { planningId }
  })
}

export const createProjectPlanningQuarter = (data: ProjectPlanningQuarterSaveVO) => {
  return request.post({ url: '/tjt/planning-quarter/create', data })
}

export const updateProjectPlanningQuarter = (data: ProjectPlanningQuarterSaveVO) => {
  return request.put({ url: '/tjt/planning-quarter/update', data })
}

export const deleteProjectPlanningQuarter = (id: number) => {
  return request.delete({ url: '/tjt/planning-quarter/delete', params: { id } })
}

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