import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { AreaForm, AreaQuery, AreaVO } from './types';

// 查询区域列表
export const listArea = (query?: AreaQuery) => {
  return request({
    url: '/system/area/list',
    method: 'get',
    params: query
  });
};

// 查询区域列表（排除节点）
export const listAreaExcludeChild = (areaId: string | number): AxiosPromise<AreaVO[]> => {
  return request({
    url: '/system/area/list/exclude/' + areaId,
    method: 'get'
  });
};

// 查询区域详细
export const getArea = (areaId: string | number): AxiosPromise<AreaVO> => {
  return request({
    url: '/system/area/' + areaId,
    method: 'get'
  });
};

// 查询区域下拉树结构
export const treeselect = (): AxiosPromise<AreaVO[]> => {
  return request({
    url: '/system/area/treeselect',
    method: 'get'
  });
};

// 新增区域
export const addArea = (data: AreaForm) => {
  return request({
    url: '/system/area',
    method: 'post',
    data: data
  });
};

// 修改区域
export const updateArea = (data: AreaForm) => {
  return request({
    url: '/system/area',
    method: 'put',
    data: data
  });
};

// 删除区域
export const delArea = (areaId: number | string) => {
  return request({
    url: '/system/area/' + areaId,
    method: 'delete'
  });
};
