import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type { ProjectRenew, ProjectRenewParam } from './model';
import { MODULES_API_URL } from '@/config/setting';

/**
 * 分页查询续费管理
 */
export async function pageProjectRenew(params: ProjectRenewParam) {
  const res = await request.get<ApiResult<PageResult<ProjectRenew>>>(
    MODULES_API_URL + '/project/project-renew/page',
    {
      params
    }
  );
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询续费管理列表
 */
export async function listProjectRenew(params?: ProjectRenewParam) {
  const res = await request.get<ApiResult<ProjectRenew[]>>(
    MODULES_API_URL + '/project/project-renew',
    {
      params
    }
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加续费管理
 */
export async function addProjectRenew(data: ProjectRenew) {
  const res = await request.post<ApiResult<unknown>>(
    MODULES_API_URL + '/project/project-renew',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改续费管理
 */
export async function updateProjectRenew(data: ProjectRenew) {
  const res = await request.put<ApiResult<unknown>>(
    MODULES_API_URL + '/project/project-renew',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除续费管理
 */
export async function removeProjectRenew(id?: number) {
  const res = await request.delete<ApiResult<unknown>>(
    MODULES_API_URL + '/project/project-renew/' + id
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量删除续费管理
 */
export async function removeBatchProjectRenew(data: (number | undefined)[]) {
  const res = await request.delete<ApiResult<unknown>>(
    MODULES_API_URL + '/project/project-renew/batch',
    {
      data
    }
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询续费管理
 */
export async function getProjectRenew(id: number) {
  const res = await request.get<ApiResult<ProjectRenew>>(
    MODULES_API_URL + '/project/project-renew/' + id
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取数据统计
 */
export async function countProjectRenew(params?: any) {
  const res = await request.get(MODULES_API_URL + '/project/project-renew/data',{
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function listMonthRenewPrice() {
  const res = await request.get(MODULES_API_URL + '/project/project-renew/listMonthRenewPrice');
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
