import { BasicPageParams } from '../model/baseModel';
import { GetModelTslParams, ModelOfMatterParams } from './model/modelOfMatterModel';
import { defHttp } from '/@/utils/http/axios';
import { FunctionType } from '/@/views/device/profiles/step/cpns/physical/cpns/config';

enum ModelOfMatter {
  CREATE = '/things_model',
  UPDATE = '/things_model',
  DELETE = '/things_model',
  TSL = '/things_model',
  LIST = '/things_model/page',
  RELEASE = '/things_model',

  GET_MODEL_SERVICE = '/things_model/get_services',
}

export const getModelList = (
  params: BasicPageParams & {
    deviceProfileId: string;
    functionTyp?: FunctionType;
    nameOrIdentifier?: string;
  }
) => {
  return defHttp.get({
    url: `${ModelOfMatter.LIST}`,
    params,
  });
};

export const getModelTsl = (params: GetModelTslParams) => {
  const { functionType, deviceProfileId } = params;
  return defHttp.get({
    url: `${ModelOfMatter.TSL}/${functionType}/${deviceProfileId}`,
  });
};

export const createModel = (params: Partial<ModelOfMatterParams>) => {
  return defHttp.post({
    url: ModelOfMatter.CREATE,
    params,
  });
};

export const updateModel = (params: Partial<ModelOfMatterParams>) => {
  return defHttp.put({
    url: ModelOfMatter.UPDATE,
    params,
  });
};

export const deleteModel = (params: string[]) => {
  return defHttp.delete({
    url: ModelOfMatter.DELETE,
    params: {
      ids: params,
    },
  });
};

export const releaseModel = (deviceProfileId: string) => {
  return defHttp.put({
    url: `${ModelOfMatter.RELEASE}/${deviceProfileId}`,
  });
};

export const getModelServices = (params: { deviceProfileId: string }) => {
  const { deviceProfileId } = params;
  return defHttp.get<ModelOfMatterParams[]>({
    url: `${ModelOfMatter.GET_MODEL_SERVICE}/${deviceProfileId}`,
  });
};
