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

export async function getCmsCompanyList(params?: API.CompanyList.Params) {
  return request<API.CompanyList.CompanyListResult>(`/api/cms/company/list`, {
    method: 'GET',
    params: params,
  });
}

export async function delCmsCompanyList(companyIds?: string) {
  return request<API.CompanyList.CompanyListResult>(`/api/cms/company/${companyIds}`, {
    method: 'DELETE',
  });
}

export async function addCmsCompanyList(params?: API.CompanyList.Params) {
  return request<API.CompanyList.CompanyListResult>(`/api/cms/company`, {
    method: 'POST',
    data: params,
  });
}

export async function putCmsCompanyList(params?: API.CompanyList.Params) {
  return request<API.CompanyList.CompanyListResult>(`/api/cms/company`, {
    method: 'PUT',
    data: params,
  });
}

export async function exportCmsCompanyList(params?: API.CompanyList.Params) {
  return downLoadXlsx(
    `/cms/company/export`,
    { params },
    `dict_data_${getDateTimeForFilename()}.xlsx`,
  );
}
