import { apiRequest } from "@/lib/api/api-service";
import { ApiResponse } from "@/types/api-response";
import { UserResponseDto } from "@/types/user";
import {
  UsersQueryParams,
  PaginatedUsersResponse,
  UserRoleResponseDto,
} from "./types";

/**
 * Admin Users Service - Example Implementation
 * Matches Backend: /api/admin/users/*
 */

const getAll = (params?: UsersQueryParams) => {
  return apiRequest<ApiResponse<PaginatedUsersResponse>>({
    url: "/admin/users",
    client: "admin",
    method: "get",
    params,
  });
};

const toggleActive = (userId: string) => {
  return apiRequest<ApiResponse<UserResponseDto>>({
    url: `/admin/users/${userId}/toggle-active`,
    client: "admin",
    method: "put",
  });
};

const assignRole = (userId: string, roleId: string) => {
  return apiRequest<ApiResponse<UserRoleResponseDto>>({
    url: `/admin/users/${userId}/roles/${roleId}`,
    client: "admin",
    method: "post",
  });
};

const removeRole = (userId: string, roleId: string) => {
  return apiRequest<ApiResponse<null>>({
    url: `/admin/users/${userId}/roles/${roleId}`,
    client: "admin",
    method: "delete",
  });
};

export const adminUsersService = {
  getAll,
  toggleActive,
  assignRole,
  removeRole,
};
