import { request } from '@umijs/max';
import { downLoadXlsx } from '@/utils/downloadfile';
import { getDateTimeForFilename } from '@/utils/tools';

export async function getCmsIndustryList(params?: API.ClassifyIndustry.Params) {
  return request<API.ClassifyIndustry.IndustryResult>(`/api/cms/industry/list`, {
    method: 'GET',
    params: params,
  });
}

export async function delCmsIndustryList(industryId?: string) {
  return request<API.ClassifyIndustry.IndustryResult>(`/api/cms/industry/${industryId}`, {
    method: 'DELETE',
  });
}

export async function getCmsIndustryTreeList() {
  return request(`/api/cms/industry/treeselect`, {
    method: 'GET',
  });
}

export async function addCmsIndustryIndustryt(params?: API.ClassifyIndustry.Params) {
  return request<API.ClassifyIndustry.IndustryTreeResult>(`/api/cms/industry`, {
    method: 'POST',
    data: params,
  });
}

export async function updateCmsIndustryIndustryt(params?: API.ClassifyIndustry.Params) {
  return request<API.ClassifyIndustry.IndustryTreeResult>(`/api/cms/industry`, {
    method: 'PUT',
    data: params,
  });
}

export async function exportCmsIndustry(params?: API.ClassifyIndustry.Params) {
  return downLoadXlsx(
    `/api/cms/industry/export`,
    { params },
    `分析_${getDateTimeForFilename()}.xlsx`,
  );
}
