import type { addressItem, addressParams } from '@/types/address'
import type { PageParams, PageResult } from '@/types/global'
import { request } from '@/utils/request'

/**
 * 添加地址
 * @param data
 * @returns
 */
export const postAddressApi = (data: addressParams) => {
  return request<addressItem>({
    method: 'POST',
    url: 'shop/userAddress/add',
    data,
  })
}

export const getAddressApi = (data?: PageParams) => {
  return request<PageResult<addressItem>>({
    method: 'GET',
    url: 'shop/userAddress',
    data,
  })
}

export const getAddressByIdApi = (id: string) => {
  return request<addressItem>({
    method: 'GET',
    url: `shop/userAddress/detail`,
    data: {
      id,
    },
  })
}

export const putAddressApi = (data: addressParams) => {
  return request<addressItem>({
    method: 'POST',
    url: `shop/userAddress/edit`,
    data,
  })
}

export const deleteAddressApi = (id: string | number) => {
  return request({
    method: 'POST',
    url: `shop/userAddress/delete`,
    data: {
      id,
    },
  })
}
