import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { RegionVO, RegionForm, RegionQuery } from '@/api/system/physical/region/types';

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

export const listRegion = (query?: RegionQuery): AxiosPromise<RegionVO[]> => {
  return request({
    url: '/physical/region/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询省市区详细
 * @param id
 */
export const getRegion = (id: string | number): AxiosPromise<RegionVO> => {
  return request({
    url: '/physical/region/' + id,
    method: 'get'
  });
};

/**
 * 新增省市区
 * @param data
 */
export const addRegion = (data: RegionForm) => {
  return request({
    url: '/physical/region',
    method: 'post',
    data: data
  });
};

/**
 * 修改省市区
 * @param data
 */
export const updateRegion = (data: RegionForm) => {
  return request({
    url: '/physical/region',
    method: 'put',
    data: data
  });
};

/**
 * 删除省市区
 * @param id
 */
export const delRegion = (id: string | number | Array<string | number>) => {
  return request({
    url: '/physical/region/' + id,
    method: 'delete'
  });
};
/**
 * 查询城市列表
 * @param parentCode 父级编码
 * @param level 层级
 */
export const selectCityList = (parentCode: string, level: string): AxiosPromise<RegionVO[]> => {
  return request({
    url: '/physical/region/selectCityList',
    method: 'get',
    params: { parentCode, level }
  });
};
