import { request } from '@/utils/request'
import type { Address, AddressSaveReq } from '@/types'

export function getAddressListApi() {
  return request<Address[]>({
    url: '/api/address',
    method: 'GET'
  })
}

export function getDefaultAddressApi() {
  return request<Address>({
    url: '/api/address/default',
    method: 'GET'
  })
}

export function getAddressDetailApi(id: number) {
  return request<Address>({
    url: `/api/address/${id}`,
    method: 'GET'
  })
}

export function createAddressApi(data: AddressSaveReq) {
  return request<number>({
    url: '/api/address',
    method: 'POST',
    data
  })
}

export function updateAddressApi(data: AddressSaveReq) {
  return request<void>({
    url: '/api/address',
    method: 'PUT',
    data
  })
}

export function deleteAddressApi(id: number) {
  return request<void>({
    url: `/api/address/${id}`,
    method: 'DELETE'
  })
}

export function setDefaultAddressApi(id: number) {
  return request<void>({
    url: `/api/address/${id}/default`,
    method: 'PUT'
  })
}
