import request from '@/utils/request'

// 查询初核项目列表
export function listProject(query) {
  return request({
    url: '/ccdi/project/list',
    method: 'get',
    params: query
  })
}

// 查询初核项目详细
export function getProject(projectId) {
  return request({
    url: '/ccdi/project/' + projectId,
    method: 'get'
  })
}

// 新增初核项目
export function addProject(data) {
  return request({
    url: '/ccdi/project',
    method: 'post',
    data: data
  })
}

// 修改初核项目
export function updateProject(data) {
  return request({
    url: '/ccdi/project',
    method: 'put',
    data: data
  })
}

// 删除初核项目
export function delProject(projectIds) {
  return request({
    url: '/ccdi/project/' + projectIds,
    method: 'delete'
  })
}

// 导出初核项目
export function exportProject(query) {
  return request({
    url: '/ccdi/project/export',
    method: 'get',
    params: query
  })
}

// 刷新项目预警人数
export function refreshWarningCount(projectId) {
  return request({
    url: '/ccdi/project/' + projectId + '/warning',
    method: 'post'
  })
}

// 归档项目
export function archiveProject(projectId) {
  return request({
    url: '/ccdi/project/' + projectId + '/archive',
    method: 'post'
  })
}

// 获取历史项目列表（用于导入）
export function listHistoryProjects(query) {
  return request({
    url: '/ccdi/project/history',
    method: 'get',
    params: query
  })
}

// 从历史项目导入
export function importFromHistory(data) {
  return request({
    url: '/ccdi/project/import',
    method: 'post',
    data: data
  })
}

// Mock数据：获取项目列表
export function getMockProjectList() {
  return Promise.resolve({
    code: 200,
    total: 3,
    rows: [
      {
        projectId: 1,
        projectName: '2024年Q1初核',
        projectDesc: '2024年第一季度纪检初核排查工作',
        createTime: '2024-01-01',
        projectStatus: '0',
        targetCount: 500,
        warningCount: 15,
        startDate: '2024-01-01',
        endDate: '2024-03-31'
      },
      {
        projectId: 2,
        projectName: '2023年Q4初核',
        projectDesc: '2023年第四季度纪检初核排查工作',
        createTime: '2023-10-01',
        projectStatus: '1',
        targetCount: 480,
        warningCount: 23,
        startDate: '2023-10-01',
        endDate: '2023-12-31'
      },
      {
        projectId: 3,
        projectName: '2023年Q3初核',
        projectDesc: '2023年第三季度纪检初核排查工作',
        createTime: '2023-07-01',
        projectStatus: '2',
        targetCount: 450,
        warningCount: 18,
        startDate: '2023-07-01',
        endDate: '2023-09-30'
      }
    ]
  })
}

// Mock数据：获取历史项目列表
export function getMockHistoryProjects() {
  return Promise.resolve({
    code: 200,
    data: [
      {
        projectId: 3,
        projectName: '2023年Q3初核',
        projectDesc: '2023年第三季度纪检初核排查工作',
        createTime: '2023-07-01',
        projectStatus: '2',
        targetCount: 450,
        warningCount: 18
      },
      {
        projectId: 4,
        projectName: '2023年Q2初核',
        projectDesc: '2023年第二季度纪检初核排查工作',
        createTime: '2023-04-01',
        projectStatus: '2',
        targetCount: 420,
        warningCount: 12
      }
    ]
  })
}
