/**
 * RBAC API 代理 - 移除用户角色
 * DELETE /api/v3/rbac/users/:userId/roles/:roleId
 */

import { json, type LoaderFunctionArgs } from "@remix-run/node";
import { removeUserRole } from "~/services/rbac-mock-data.server";

// DELETE - 移除用户角色
export async function action({ params }: LoaderFunctionArgs) {
  const userId = parseInt(params.userId || '0');
  const roleId = parseInt(params.roleId || '0');

  console.log('📡 [API Route] DELETE /api/v3/rbac/users/' + userId + '/roles/' + roleId);

  // 使用共享Mock数据移除角色
  const success = removeUserRole(userId, roleId);

  if (success) {

    return json({
      code: 200,
      message: '用户角色移除成功'
    });
  }

  return json({
    detail: '用户角色关联不存在'
  }, { status: 404 });
}
