import request from '@/config/axios'

export interface ProjectProfitVO {
  projectId: number
  projectName: string
  sortNo?: string
  contractSignedFlag: boolean
  contractAmount?: number
  finalSettlementAmount?: number
  effectiveSettlementAmount?: number
  comprehensivePlanningAmount?: number
  subcontractPlanningAmount?: number
  specialSubcontractPlanningAmount?: number
  sourceCoopSubcontractPlanningAmount?: number
  comprehensiveSubcontractPlanningAmount?: number
  majorOutputValue?: number
  majorExpectedPerformance?: number
  innovationOutputRate?: number
  innovationOutputValue?: number
  otherCost?: number
  profitLossValue?: number
  profitLossRate?: number
  projectStartYear?: number
  createTime?: string
  budgetSnapshot?: ProjectProfitSnapshotVO
  accountingSnapshot?: ProjectProfitSnapshotVO
  settlementSnapshot?: ProjectProfitSnapshotVO
}

export interface ProjectProfitSnapshotVO {
  id?: number
  projectId: number
  snapshotType: 'budget' | 'accounting' | 'settlement'
  lockedFlag?: boolean
  actionUserId?: number
  actionUserName?: string
  actionTime?: string
  contractAmount?: number
  finalSettlementAmount?: number
  effectiveSettlementAmount?: number
  comprehensivePlanningAmount?: number
  subcontractPlanningAmount?: number
  specialSubcontractPlanningAmount?: number
  sourceCoopSubcontractPlanningAmount?: number
  comprehensiveSubcontractPlanningAmount?: number
  majorOutputValue?: number
  majorExpectedPerformance?: number
  innovationOutputRate?: number
  innovationOutputValue?: number
  otherCost?: number
  profitLossValue?: number
  profitLossRate?: number
  assessmentResult?: string
  assessmentCoefficient?: number
  comprehensiveAccountingOutputValue?: number
  comprehensiveSettlementOutputValue?: number
  majorAccountingOutputValue?: number
  majorSettlementOutputValue?: number
  remark?: string
}

export interface ProjectProfitSettlementSaveReqVO {
  projectId: number
  assessmentResult?: string
  remark?: string
}

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

export const getProjectProfitPage = (params: ProjectProfitPageReqVO) => {
  return request.get({ url: '/tjt/profit/page', params })
}

export const getProjectProfit = (projectId: number) => {
  return request.get({ url: '/tjt/profit/get', params: { projectId } })
}

export const lockBudgetSnapshot = (projectId: number) => {
  return request.post({ url: '/tjt/profit/lock-budget', params: { projectId } })
}

export const lockAccountingSnapshot = (projectId: number) => {
  return request.post({ url: '/tjt/profit/lock-accounting', params: { projectId } })
}

export const saveSettlementSnapshot = (data: ProjectProfitSettlementSaveReqVO) => {
  return request.put({ url: '/tjt/profit/save-settlement', data })
}
