/**
 * @description 权限相关API
 * @author yslg
 * @since 2025-10-06
 */
import { api } from '@/apis/index';
import { SysPermission, ResultDomain } from '@/types';


export const permissionApi = {

  /**
   * @description    获取权限信息
   * @param    permission 权限
   * @author    yslg
   * @ since 2025-10-08
   */
  async getPermission(permission: SysPermission|null=null): Promise<ResultDomain<SysPermission>> {
    const response = await api.get<SysPermission>('/permissions/permission', permission);
    return response.data;
  },

  /**
   * @description    添加权限
   * @param    permission 权限
   * @author    yslg
   * @ since 2025-10-08
   */
  async addPermission(permission: SysPermission): Promise<ResultDomain<SysPermission>> {
    const response = await api.post<SysPermission>('/permissions/permission', permission);
    return response.data;
  },

  /**
   * @description    更新权限
   * @param    permission 权限
   * @author    yslg
   * @ since 2025-10-08
   */
  async updatePermission(permission: SysPermission): Promise<ResultDomain<SysPermission>> {
    const response = await api.put<SysPermission>('/permissions/permission', permission);
    return response.data;
  },

  /**
   * @description    删除权限
   * @param    permission 权限
   * @author    yslg
   * @ since 2025-10-08
   */
  async deletePermission(permission: SysPermission): Promise<ResultDomain<SysPermission>> {
    const response = await api.delete<SysPermission>('/permissions/permission', permission);
    return response.data;
  },

  /**
   * @description    获取权限列表
   * @param    permission 权限
   * @author    yslg
   * @ since 2025-10-08
   */
  async getPermissionList(permission: SysPermission|null=null): Promise<ResultDomain<SysPermission>> {
    const response = await api.post<SysPermission>('/permissions/list', permission);
    return response.data;
  },

  /**
   * @description    获取权限绑定菜单
   * @param    permission 权限
   * @author    yslg
   * @ since 2025-10-08
   */
  async getPermissionBindingList(permission: SysPermission): Promise<ResultDomain<SysPermission>> {
    const response = await api.post<SysPermission>('/permissions/list/binding', permission);
    return response.data;
  },

  /**
   * @description    绑定权限菜单
   * @param    permission 权限
   * @author    yslg
   * @ since 2025-10-08
   */
  async bindMenu(permission: SysPermission): Promise<ResultDomain<SysPermission>> {
    const response = await api.post<SysPermission>('/permissions/bind/menu', permission);
    return response.data;
  },

  /**
   * @description    绑定权限角色
   * @param    permission 权限
   * @author    yslg
   * @ since 2025-10-08
   */
  async bindRole(permission: SysPermission): Promise<ResultDomain<SysPermission>> {
    const response = await api.post<SysPermission>('/permissions/bind/role', permission);
    return response.data;
  },

  /**
   * @description    解绑权限菜单
   * @param    permission 权限
   * @author    yslg
   * @ since 2025-10-08
   */
  async unbindMenu(permission: SysPermission): Promise<ResultDomain<SysPermission>> {
    const response = await api.post<SysPermission>('/permissions/unbind/menu', permission);
    return response.data;
  },

  /**
   * @description    解绑权限角色
   * @param    permission 权限
   * @author    yslg
   * @ since 2025-10-08
   */
  async unbindRole(permission: SysPermission): Promise<ResultDomain<SysPermission>> {
    const response = await api.post<SysPermission>('/permissions/unbind/role', permission);
    return response.data;
  }
}