import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import { request } from '@/plugins/http-fetch';
import { parseObjLineToHump } from '@/utils/parse-utils';

/**
 * 查询UDM可用cmd命令
 * @returns object
 */
export async function getMMLByUDM() {
  // 发起请求
  const result = await request({
    url: `/api/rest/databaseManagement/v1/elementType/omc_db/objectType/mml_subscriber`,
    method: 'get',
    params: {
      SQL: `select * from mml_subscriber where ne_type = 'UDM'`,
    },
  });
  // 解析数据
  if (result.code === RESULT_CODE_SUCCESS && Array.isArray(result.data.data)) {
    let data = result.data.data[0];
    return Object.assign(result, {
      data: parseObjLineToHump(data['mml_subscriber']),
    });
  }
  return result;
}

/**
 * 发送UDM的mml命令
 * @param neId 网元ID
 * @param cmdStr 命令串
 * @returns
 */
export async function sendMMlByUDM(
  neId: string,
  cmdStr: string
) {
  // 发起请求
  const result = await request({
    url: `/api/rest/operationManagement/v1/elementType/UDM/objectType/mml?ne_id=${neId}`,
    method: 'post',
    data: { mml: [cmdStr] },
  });
  // 解析数据
  if (result.code === RESULT_CODE_SUCCESS && Array.isArray(result.data.data)) {
    result.data = result.data.data[0];
  }
  return result;
}
