import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { AddressareaVO, AddressareaForm, AddressareaQuery } from '@/api/system/addressarea/types';

// API functions for address area management

/**
 * 查询地区列表列表
 * @param query
 * @returns {*}
 */

export const listAddressarea = (query?: AddressareaQuery): AxiosPromise<AddressareaVO[]> => {
  return request({
    url: '/system/addressarea/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询省市列表列表
 * @param query
 * @returns {*}
 */

export const chinaAreaList = (query?: AddressareaQuery): AxiosPromise<AddressareaVO[]> => {
  return request({
    url: '/system/addressarea/getChinaList',
    method: 'get',
    params: query
  });
};

/**
 * 查询地区列表详细
 * @param id
 */
export const getAddressarea = (id: string | number): AxiosPromise<AddressareaVO> => {
  return request({
    url: '/system/addressarea/' + id,
    method: 'get'
  });
};

/**
 * 新增地区列表
 * @param data
 */
export const addAddressarea = (data: AddressareaForm) => {
  return request({
    url: '/system/addressarea',
    method: 'post',
    data: data
  });
};

/**
 * 修改地区列表
 * @param data
 */
export const updateAddressarea = (data: AddressareaForm) => {
  return request({
    url: '/system/addressarea',
    method: 'put',
    data: data
  });
};

/**
 * 删除地区列表
 * @param id
 */
export const delAddressarea = (id: string | number | Array<string | number>) => {
  return request({
    url: '/system/addressarea/' + id,
    method: 'delete'
  });
};

export const getChinaArea = (): AxiosPromise<AddressareaVO[]> => {
  return request({
    url: '/system/addressarea/getchina/area',
    method: 'get'
  });
};

