import { defHttp } from '/@/utils/http/axios';
import {
  // ScreenParamModel,
  ScreenAddModel,
  ScreenLinkPageQueryParam,
  ScreenByDeptIdParams,
  IChangeStatus,
} from '/@/api/ruleengine/model/ruleengineModel';

enum ScreenManagerApi {
  /**
   * 场景URL
   */
  SCREEN_GET_URL = '/scene_linkage',
  SCREEN_ADD_URL = '/scene_linkage',
  SCREEN_DELETE_URL = '/scene_linkage',
  SCREEN_UPDATE_URL = '/scene_linkage/update',
  SCREEN_ORGANIZATION_URL = '/organization/me/list',
  SCREEN_CHANGE_STATUS = '/convert/update/scene',
  SCREEN_GET_BY_DEPTID = '/scene_linkage/device/',
  // GET_ATTRBUTELIST = '/device/keys',
  GET_ATTRBUTELIST = '/device/attributes/',
  ALARM_PROFILE = '/alarm/profile/',
  MASTER_GET_DEVICE = '/device/list',
}

/**
 * 获取部门id
 * @param 无参数
 */
export const screenLinkOrganizationGetApi = () => {
  return defHttp.get({
    url: ScreenManagerApi.SCREEN_ORGANIZATION_URL,
  });
};

/**
 * 分页查询场景联动表格页面
 * @param params pageSize page name
 */
export const screenLinkPageGetApi = (params?: ScreenLinkPageQueryParam) => {
  return defHttp.get({
    url: ScreenManagerApi.SCREEN_GET_URL,
    params,
  });
};

/**
 * 新增或更新场景联动
 * @param params pageSize page name
 */
export const screenLinkPageAddApi = (params: ScreenAddModel, isUpdate: boolean) => {
  return defHttp.post<ScreenAddModel>({
    url: isUpdate ? ScreenManagerApi.SCREEN_UPDATE_URL : ScreenManagerApi.SCREEN_ADD_URL,
    params,
  });
};

/**
 * 删除场景联动
 * @param params pageSize page name
 */
export const screenLinkPageDeleteApi = (ids: string[]) => {
  return defHttp.delete({
    url: ScreenManagerApi.SCREEN_DELETE_URL,
    data: {
      ids,
    },
  });
};

/**
 * 改变场景联动状态
 * @param params id status
 */
export const screenLinkPagePutApi = (params: IChangeStatus) =>
  defHttp.post({
    url: ScreenManagerApi.SCREEN_CHANGE_STATUS,
    data: params,
  });

/**
 * 根据组织获取设备列表
 */
export const screenLinkPageByDeptIdGetDevice = (params: ScreenByDeptIdParams) => {
  return defHttp.get({
    url: ScreenManagerApi.SCREEN_GET_BY_DEPTID,
    params,
  });
};

/**
 * 获取组织下的告警配置
 */
export const getOrganizationAlarmConfig = (params: { organizationId }) => {
  return defHttp.get({
    url: ScreenManagerApi.ALARM_PROFILE + params.organizationId,
  });
};

//TODO-fengtao
/**
 * 获取设备属性列表
 */
// export const getAttribute = (orgId, deviceIds) => {
//   const joinText = deviceIds == null ? [] : '?deviceIds=' + deviceIds;
//   return defHttp.get({
//     url: ScreenManagerApi.GET_ATTRBUTELIST + '/' + orgId + joinText,
//   });
// };
export const getAttribute = (orgId) => {
  // const joinText = deviceIds == null ? [] : '?deviceIds=' + deviceIds;
  return defHttp.get({
    url: `${ScreenManagerApi.GET_ATTRBUTELIST}${orgId}`,
  });
};

/**
 * 获取主设备列表（exclude子设备）---执行动作
 * @param params organizationId
 */
export const byOrganizationIdGetMasterDevice = (params: {
  organizationId: string;
  deviceProfileId?: string;
}) => {
  const { organizationId, deviceProfileId } = params;
  return defHttp.get({
    url: `${ScreenManagerApi.MASTER_GET_DEVICE}`,
    params: { deviceProfileId, organizationId },
  });
};
//TODO-fengtao
