/*
 * @Author: Badguy
 * @Date: 2022-04-13 14:35:17
 * @LastEditTime: 2022-05-13 09:26:03
 * @LastEditors: your name
 * @Description: 数据整合接口
 * have a nice day!
 */

import request from '@/utils/request'
import { Message } from 'element-ui'

export function GeneralDataReception(params) {
  return request({
    url: '/openApi/generalDataReception',
    method: 'post',
    headers: {
      'content-type': 'application/json'
    },
    data: params
  })
}

export function Query(params) {
  return request({
    url: '/openApi/query',
    method: 'post',
    headers: {
      'content-type': 'application/json'
    },
    data: params
  })
}

export const queryMap = {
  protocol: 1,
  node: 2,
  service: 3,
  source: 4,
  sourceItem: 5,
  serviceAndSource: 6,
  target: 7,
  targetItem: 8,
  serviceAndOutput: 9,
  serviceAndNode: 10,
  serviceByID: 11,
  nodeByServiceID: 12,
  sourceByServiceID: 13,
  targetByServiceID: 14,
  targetItemByTargetID: 15,
  sourceItemBySourceID: 16,
  targetByID: 17,
  sourceByID: 18,
  serviceAlgorithmByServiceID: 19,
  outputListByServiceID: 20,
  advacedQuery: 30,
  departureAirPort: 31,
  landingAirport: 32,
  departureAirPortBylandingAirport: 33,
  landingAirportBydepartureAirPort: 34,
  carrier: 35,
  craftType: 36,
  flightAttr: 37,
  landingFlight: 38,
  departureFlight: 39,
  transferFlight: 40,
  container: 41,
  baggageDetailsByID: 44,
  baggageBasicInfoByID: 45,
  baggageByFlightNO: 46,
  transferInBaggage: 47,
  transferOutBaggage: 48,
  flightInfo: 49,
  baggageTrackByID: 61,
  message: 75,
  baggageType: 86
}

export async function myQuery(id, ...dataContent) {
  const params = {
    id,
    dataContent
  }
  try {
    const result = await Query(params)
    if (Number(result.code) === 0) {
      return result.returnData
    } else {
      Message.error(result.message ?? '失败')
      return Promise.reject(result.message)
    }
  } catch (error) {
    return Promise.reject(error)
  }
}
