import { request } from '../../boot/axios';
import { Pagination } from '../class';
import {
  AssignUsersFormData,
  GrantFormData,
  RoleAddOrEditForm,
  RoleSearchEntity
} from './model/userRole';

class RoleApi {
  getPage = (val?: Pagination<RoleSearchEntity>) => {
    return request.postForPage('role/page', val);
  };
  insertOrUpdate = (val?: RoleAddOrEditForm) => {
    return request.post('role/save', val);
  };
  getWarehouseList = (val?: string) => {
    return request.post('warehouse/list', { warehouseName: val });
  };
  getMenusByRoleId = (val?: number) => {
    return request.get('menu/getMenusByRoleId/' + val);
  };
  treeList = () => {
    return request.get('menu/treeList');
  };
  grantMenusAuth = (val?: GrantFormData) => {
    return request.post('role/grantMenusAuth', val);
  };
  del = (val?: number) => {
    return request.get('role/delete/' + val);
  };
  getUsersRolesByRoleId = (val?: number) => {
    return request.get('role/getUsersRolesByRoleId/' + val);
  };
  checkBoxList = () => {
    return request.get('user/check-box-list');
  };
  assign = (val?: AssignUsersFormData) => {
    return request.post('role/assign', val);
  };
}
const roleApi = new RoleApi();
export { roleApi };
