import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { LevelVO, LevelForm, LevelQuery } from '@/api/system/level/types';

/**
 * 查询供应商等级列表
 * @param query
 * @returns {*}
 */

export const listLevel = (query?: LevelQuery): AxiosPromise<LevelVO[]> => {
  return request({
    url: '/system/level/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询供应商等级详细
 * @param datasource
 * @param supplierLevelNo
 */
export const getLevel = (datasource: string, supplierLevelNo: string): AxiosPromise<LevelVO> => {
  return request({
    url: '/system/level/' + datasource + '/' + supplierLevelNo,
    method: 'get'
  });
};

/**
 * 新增供应商等级
 * @param data
 */
export const addLevel = (data: LevelForm) => {
  return request({
    url: '/system/level',
    method: 'post',
    data: data
  });
};

/**
 * 修改供应商等级
 * @param data
 */
export const updateLevel = (data: LevelForm) => {
  return request({
    url: '/system/level',
    method: 'put',
    data: data
  });
};

/**
 * 删除供应商等级
 * @param supplierLevelNo
 */
export const delLevel = (supplierLevelNo: string | Array<string>) => {
  return request({
    url: '/system/level/' + supplierLevelNo,
    method: 'delete'
  });
};

/**
 * 获取数据来源列表
 */
export const getDataSourceList = (): AxiosPromise<{ dataSourceNm: string }[]> => {
  return request({
    url: '/system/datasource/GetDataSourceList',
    method: 'get'
  });
};
