package dev.lions.user.manager.client.api;

import dev.lions.user.manager.client.filter.AuthHeaderFactory;
import dev.lions.user.manager.dto.role.RoleAssignmentDTO;
import dev.lions.user.manager.dto.role.RoleDTO;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import java.util.List;

@RegisterRestClient(configKey = "user-api")
@RegisterClientHeaders(AuthHeaderFactory.class)
@Path("/api/roles")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface RoleRestClient {

        @GET
        @Path("/realm")
        List<RoleDTO> getAllRealmRoles(@QueryParam("realm") String realmName);

        @POST
        @Path("/realm")
        RoleDTO createRealmRole(@QueryParam("realm") String realmName, RoleDTO role);

        @GET
        @Path("/realm/{roleName}")
        RoleDTO getRealmRole(@PathParam("roleName") String roleName, @QueryParam("realm") String realmName);

        @PUT
        @Path("/realm/{roleName}")
        RoleDTO updateRealmRole(@PathParam("roleName") String roleName, @QueryParam("realm") String realmName,
                        RoleDTO role);

        @DELETE
        @Path("/realm/{roleName}")
        void deleteRealmRole(@PathParam("roleName") String roleName, @QueryParam("realm") String realmName);

        @POST
        @Path("/users/{userId}/realm-roles")
        void assignRealmRoles(@PathParam("userId") String userId, @QueryParam("realm") String realmName,
                        RoleAssignmentRequest request);

        @DELETE
        @Path("/users/{userId}/realm-roles")
        void revokeRealmRoles(@PathParam("userId") String userId, @QueryParam("realm") String realmName,
                        RoleAssignmentRequest request);

        @GET
        @Path("/users/{userId}/realm-roles")
        List<RoleDTO> getUserRealmRoles(@PathParam("userId") String userId, @QueryParam("realm") String realmName);

        // Inner class for role assignment request
        class RoleAssignmentRequest {
                public List<String> roleNames;
        }
}
