import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { TypeVO, TypeForm, TypeQuery } from '@/api/system/type/types';

/**
 * 查询供应商类别列表
 * @param query
 * @returns {*}
 */

export const listType = (query?: TypeQuery): AxiosPromise<TypeVO[]> => {
  return request({
    url: '/system/type/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询供应商类别详细
 * @param datasource
 * @param supplierTypeNo
 */
export const getType = (datasource: string, supplierTypeNo: string): AxiosPromise<TypeVO> => {
  return request({
    url: '/system/type/' + datasource + '/' + supplierTypeNo,
    method: 'get'
  });
};

/**
 * 新增供应商类别
 * @param data
 */
export const addType = (data: TypeForm) => {
  return request({
    url: '/system/type',
    method: 'post',
    data: data
  });
};

/**
 * 修改供应商类别
 * @param data
 */
export const updateType = (data: TypeForm) => {
  return request({
    url: '/system/type',
    method: 'put',
    data: data
  });
};

/**
 * 删除供应商类别
 * @param supplierTypeNo
 */
export const delType = (supplierTypeNo: string | Array<string>) => {
  return request({
    url: '/system/type/' + supplierTypeNo,
    method: 'delete'
  });
};

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