import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { AddressVO, AddressForm, AddressQuery } from '@/api/supplier/address/types';

/**
 * 查询供应商地址列表
 * @param query
 * @returns {*}
 */

export const listAddress = (query?: AddressQuery): AxiosPromise<AddressVO[]> => {
  return request({
    url: '/customer/supplieraddress/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询供应商地址详细
 * @param id
 */
export const getAddress = (id: string | number): AxiosPromise<AddressVO> => {
  return request({
    url: '/customer/supplieraddress/' + id,
    method: 'get'
  });
};

/**
 * 新增供应商地址
 * @param data
 */
export const addAddress = (data: AddressForm) => {
  return request({
    url: '/customer/supplieraddress',
    method: 'post',
    data: data
  });
};

/**
 * 修改供应商地址
 * @param data
 */
export const updateAddress = (data: AddressForm) => {
  return request({
    url: '/customer/supplieraddress',
    method: 'put',
    data: data
  });
};

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

/**
 * 设置默认地址
 * @param id
 * @param defaultAddress 状态
 */
export function changeDefaultAddress(id: string | number, isSelf: string) {
  const data = {
    id,
    isSelf
  };
  return request({
    url: '/customer/supplieraddress/changeDefaultAddress',
    method: 'put',
    data: data
  });
}
