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

/**
 * 查询网元可用cmd命令
 * @param neType 网元类型
 * @returns object
 */
export async function getMMLByNE(neType: string) {
  // 发起请求
  const result = await request({
    url: `/api/rest/databaseManagement/v1/elementType/omc_db/objectType/mml_system`,
    method: 'get',
    params: {
      SQL: `select * from mml_system where ne_type = '${neType}'`,
    },
  });
  // 解析数据
  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_system']),
    });
  }
  return result;
}

/**
 * 发送网元的mml命令
 * @param neType 网元类型
 * @param neId 网元ID
 * @param cmdStr 命令串
 * @returns
 */
export async function sendMMlByNE(
  neType: string,
  neId: string,
  cmdStr: string
) {
  // 发起请求
  const result = await request({
    url: `/api/rest/operationManagement/v1/elementType/${neType}/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;
}
