import { defHttp } from '/@/utils/http/axios';
import type {
  queryPageParams,
  ConfigurationCenterParams,
  ConfigurationCenterInfo,
  ConfigurationCenterItemsModal,
} from './model/configurationCenterModal';
import { getPageData } from '../../base';
import { FileUploadResponse } from '../../oem/model';
enum API {
  basicUrl = '/configuration/center',
  UPLOAD = '/oss/upload',
}

export const getPage = (params: queryPageParams) => {
  return getPageData<ConfigurationCenterItemsModal>(params, API.basicUrl);
};

export const saveConfigurationCenter = (params: ConfigurationCenterParams) => {
  return defHttp.post({
    url: API.basicUrl,
    data: params,
  });
};

export const updateConfigurationCenter = (params: ConfigurationCenterParams) => {
  return defHttp.put({
    url: API.basicUrl,
    data: params,
  });
};

export const deleteConfigurationCenter = (ids: string[]) => {
  return defHttp.delete({
    url: API.basicUrl,
    data: {
      ids: ids,
    },
  });
};

export const saveOrUpdateConfigurationCenter = (
  params: ConfigurationCenterInfo,
  isUpdate: boolean
) => {
  return isUpdate ? updateConfigurationCenter(params) : saveConfigurationCenter(params);
};

export const uploadThumbnail = (file: FormData) => {
  return defHttp.post<FileUploadResponse>({ url: API.UPLOAD, params: file });
};
