import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ShippingAddressVO, ShippingAddressForm, ShippingAddressQuery } from '@/api/customer/customerFile/shippingAddress/types';

/**
 * 查询客户收货地址列表
 * @param query
 * @returns {*}
 */

export const listShippingAddress = (query?: ShippingAddressQuery): AxiosPromise<ShippingAddressVO[]> => {
  return request({
    url: '/customer/shippingAddress/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询客户收货地址详细
 * @param id
 */
export const getShippingAddress = (id: string | number): AxiosPromise<ShippingAddressVO> => {
  return request({
    url: '/customer/shippingAddress/' + id,
    method: 'get'
  });
};

/**
 * 新增客户收货地址
 * @param data
 */
export const addShippingAddress = (data: ShippingAddressForm) => {
  return request({
    url: '/customer/shippingAddress',
    method: 'post',
    data: data
  });
};

/**
 * 修改客户收货地址
 * @param data
 */
export const updateShippingAddress = (data: ShippingAddressForm) => {
  return request({
    url: '/customer/shippingAddress',
    method: 'put',
    data: data
  });
};

/**
 * 删除客户收货地址
 * @param id
 */
export const delShippingAddress = (id: string | number | Array<string | number>) => {
  return request({
    url: '/customer/shippingAddress/' + id,
    method: 'delete'
  });
};

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