import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { MutexGroupQuery, MutexGroupVO, MutexGroupForm } from './types';

// 查询菜单互斥组列表
export const listMutexGroup = (query?: MutexGroupQuery): AxiosPromise<MutexGroupVO[]> => {
  return request({
    url: '/system/menuMutexGroup/list',
    method: 'get',
    params: query
  });
};

// 根据互斥组ID获取详细信息
export const getMutexGroup = (groupId: string | number): AxiosPromise<MutexGroupVO> => {
  return request({
    url: `/system/menuMutexGroup/${groupId}`,
    method: 'get'
  });
};

// 新增菜单互斥组
export const addMutexGroup = (data: MutexGroupForm) => {
  return request({
    url: '/system/menuMutexGroup/add',
    method: 'post',
    data: data
  });
};

// 修改菜单互斥组
export const updateMutexGroup = (data: MutexGroupForm) => {
  return request({
    url: '/system/menuMutexGroup/edit',
    method: 'post',
    data: data
  });
};

// 删除菜单互斥组
export const deleteMutexGroup = (groupIds: (string | number)[] | string | number) => {
  return request({
    url: `/system/menuMutexGroup/remove/${groupIds}`,
    method: 'post'
  });
};

// 修改互斥组状态
export const changeGroupStatus = (groupId: string | number, status: string) => {
  const data = {
    groupId,
    status
  };
  return request({
    url: '/system/menuMutexGroup/changeStatus',
    method: 'post',
    data: data
  });
};

// 检查菜单互斥
export const checkMenuMutex = (menuIds: number[]): AxiosPromise<MutexGroupVO[]> => {
  return request({
    url: '/system/menuMutexGroup/checkMutex',
    method: 'post',
    data: menuIds
  });
};

// 根据互斥组ID查询菜单列表
export const getGroupMenuTreeselect = (groupId: string | number): AxiosPromise<number[]> => {
  return request({
    url: `/system/menuMutexGroup/groupMenuTreeselect/${groupId}`,
    method: 'get'
  });
};

// 导出菜单互斥组列表
export const exportMutexGroup = (query?: MutexGroupQuery) => {
  return request({
    url: '/system/menuMutexGroup/export',
    method: 'post',
    params: query,
    responseType: 'blob'
  });
};
