import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { InfoVO, InfoForm, InfoQuery } from '@/api/customer/info/types';

/**
 * 查询供应商信息列表
 * @param query
 * @returns {*}
 */

export const listInfo = (query?: InfoQuery): AxiosPromise<InfoVO[]> => {
  return request({
    url: '/customer/info/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询供应商信息详细
 * @param id
 */
export const getInfo = (id: string | number): AxiosPromise<InfoVO> => {
  return request({
    url: '/customer/info/' + id,
    method: 'get'
  });
};

/**
 * 新增供应商信息
 * @param data
 */
export const addInfo = (data: InfoForm) => {
  return request({
    url: '/customer/info',
    method: 'post',
    data: data
  });
};

/**
 * 修改供应商信息
 * @param data
 */
export const updateInfo = (data: InfoForm) => {
  return request({
    url: '/customer/info',
    method: 'put',
    data: data
  });
};

/**
 * SCM修改供应商信息（不走审核）
 * @param data
 */
export const scmEditInfo = (data: InfoForm) => {
  return request({
    url: '/customer/info/scm',
    method: 'put',
    data: data
  });
};

/**
 * 删除供应商信息
 * @param id
 */
export const delInfo = (id: string | number | Array<string | number>) => {
  return request({
    url: '/customer/info/' + id,
    method: 'delete'
  });
};


/**
 * 获取供应商类型列表
 */
export const getComSupTyList = () => {
  return request({
    url: '/system/type/getComSupTyList',
    method: 'get'
  });
};
/**
 * 获取产品分类列表
 */
export const getProductCategoryList = () => {
  return request({
    url: '/product/category/getProductCategoryList',
    method: 'get'
  });
};
/**
 * 获取人员信息列表
 */
export const getComStaffList = (params?: any) => {
  return request({
    url: '/system/comStaff/list',
    method: 'get',
    params: params
  });
};
/**
 * 获取字典数据
 */
export const getDictData = (dictType: string) => {
  return request({
    url: `/system/dict/data/type/${dictType}`,
    method: 'get'
  });
};

/**
 * 查询供应商信息列表（新接口，包含产品经理和采购员）
 * @param query
 * @returns {*}
 */
export const getInfoList = (query?: InfoQuery): AxiosPromise<InfoVO[]> => {
  return request({
    url: '/customer/info/getList',
    method: 'get',
    params: query
  });
};

/**
 * 查询待审核供应商信息列表
 * @param query
 * @returns {*}
 */
export const getApproveList = (query?: InfoQuery): AxiosPromise<InfoVO[]> => {
  return request({
    url: '/customer/info/getApproveList',
    method: 'get',
    params: query
  });
};

/**
 * 根据供应商ID获取人员信息
 * @param supplierId 供应商ID
 */
export const getStaffInfoById = (supplierId: string | number) => {
  return request({
    url: '/system/comStaff/informationById',
    method: 'get',
    params: { supplierId }
  });
};

/**
 * 获取所有人员信息（用于下拉框）
 */
export const getStaffListSplice = () => {
  return request({
    url: '/system/comStaff/listSplice',
    method: 'get'
  });
};

/**
 * 根据供应商ID获取产品经理和采购员ID
 * @param supplierId 供应商ID
 */
export const getSupplierStaffIds = (supplierId: string | number) => {
  return request({
    url: '/system/comStaff/informationById',
    method: 'get',
    params: { supplierId: supplierId }
  });
};

/**
 * 根据供应商ID获取联系人列表
 * @param supplierId 供应商ID
 * @param params 分页参数
 */
export const getContactListById = (supplierId: string | number, params?: any) => {
  return request({
    url: '/customer/contact/getSupplierContactlistById',
    method: 'get',
    params: {
      supplierId: supplierId,
      ...params
    }
  });
};

/**
 * 根据供应商ID获取已选择的品目ID列表
 * @param supplierId 供应商ID
 * @param supplyStatus 供应商状态（可选）
 */
export const getSupplierCategories = (supplierId: string | number, supplyStatus?: string) => {
  return request({
    url: '/customer/info/getSupplierCategories',
    method: 'get',
    params: { supplierId, supplyStatus }
  });
};

/**
 * 根据供应商ID获取合同列表
 * @param supplierId 供应商ID
 * @param params 查询参数
 */
export const getSupplierContractsById = (supplierId: string | number, params?: any) => {
  return request({
    url: '/customer/supplierContract/supplierContractsById',
    method: 'get',
    params: {
      supplierId: supplierId,
      ...params
    }
  });
};

/**
 * 根据供应商ID获取合同列表（新接口）
 * @param supplierId 供应商ID
 * @param params 查询参数
 */
export const getContractListById = (supplierId: string | number, params?: any) => {
  return request({
    url: '/customer/supplierContract/getListbyId',
    method: 'get',
    params: {
      supplierId: supplierId,
      ...params
    }
  });
};

/**
 * 根据供应商ID获取银行账户信息
 * @param id 供应商ID
 */
export const getBankBySupplierId = (id: string | number) => {
  return request({
    url: '/customer/supplierbank/getBankBySupplierId',
    method: 'get',
    params: { id }
  });
};

/**
 * 根据供应商ID获取授权详情列表（支持分页）
 * @param params 查询参数，包含supplierId和分页参数
 */
export const getAuthorizeDetailList = (params: any) => {
  return request({
    url: '/customer/supplierauthorize/getAuthorizeDetailList',
    method: 'get',
    params: params
  });
};

/**
 * 保存供应商采购信息(产品经理和采购员)
 * @param data 采购信息数据
 */
export const savePurchaseInfo = (data: { supplierId: string | number; productManager: number | null; purchaser: number | null }) => {
  return request({
    url: '/customer/procurement',
    method: 'post',
    data: data
  });
};


/**
 * 根据供应商ID获取地址列表
 * @param supplierId 供应商ID
 */
export const getSupplierAddressById = (supplierId: string | number) => {
  return request({
    url: '/customer/supplieraddress/supplierAddressById',
    method: 'get',
    params: { supplierId }
  });
};

/**
 * 获取公司列表
 */
export const getCompanyList = (params?: any) => {
  return request({
    url: '/system/company/list',
    method: 'get',
    params
  });
};

/**
 * 获取供应商类型列表
 */
export const getSupplierTypeList = (params?: any) => {
  return request({
    url: '/system/type/list',
    method: 'get',
    params: {


      dataSource: 'youyi',
      ...params
    }
  });
};

/**
 * 获取供应商等级列表
 */
export const getSupplierLevelList = () => {
  return request({
    url: '/system/level/list',
    method: 'get'
  });
};

/**
 * 获取企业规模列表
 */
export const getEnterpriseScaleList = () => {
  return request({
    url: '/customer/enterpriseScale/getlist',
    method: 'get'
  });
};

/**
 * 获取行业类别列表
 */
export const getIndustryCategoryList = () => {
  return request({
    url: '/customer/industryCategory/getlist',
    method: 'get'
  });
};

/**
 * 获取税率列表
 */
export const getTaxRateList = () => {
  return request({
    url: '/system/taxrate/list',
    method: 'get'
  });
};

/**
 * 获取结算方式列表
 */
export const getSettlementMethodList = () => {
  return request({
    url: '/system/settlementMethod/list',
    method: 'get'
  });
};

/**
 * 获取发票类型列表
 */
export const getInvoiceTypeList = () => {
  return request({
    url: '/system/invoiceType/list',
    method: 'get'
  });
};
