import { defHttp } from '/@/utils/http/axios';

import { DeptListGetResultModel, DeptListItem } from '/@/api/system/model/deptModel';

import { DeptOperationApiResult, DeptOperationParams } from '/@/api/system/model/deptModel';
import { ErrorMessageMode } from '/#/axios';

enum Api {
  DeptList = '/dept/all',
  basicUrl = '/dept',
}

export const getDeptList = (params?: DeptListItem) =>
  defHttp.get<DeptListGetResultModel>({ url: Api.DeptList, params });

/**
 * @description: save or edit dept api
 */
export function saveOrEditDeptApi(
  params: DeptOperationParams,
  update = false,
  mode: ErrorMessageMode = 'modal'
) {
  if (!update) {
    return defHttp.post<DeptOperationApiResult>(
      {
        url: Api.basicUrl,
        params,
      },
      {
        errorMessageMode: mode,
      }
    );
  } else {
    return defHttp.put<DeptOperationApiResult>(
      { url: Api.basicUrl, params },
      { errorMessageMode: mode }
    );
  }
}

export const delDept = (menuIds: string[]) => {
  const url = Api.basicUrl;
  return defHttp.delete({ url: url, data: menuIds });
};
