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

import dev.lions.user.manager.dto.role.RoleAssignmentDTO;
import dev.lions.user.manager.dto.role.RoleDTO;
import dev.lions.user.manager.enums.role.TypeRole;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import java.util.List;

/**
 * REST Client pour le service de gestion des rôles
 */
@Path("/api/roles")
@RegisterRestClient(configKey = "lions-user-manager-api")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface RoleServiceClient {

    // ==================== Realm Roles ====================

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

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

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

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

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

    // ==================== Client Roles ====================

    @POST
    @Path("/client")
    RoleDTO createClientRole(
        RoleDTO role,
        @QueryParam("realm") String realmName,
        @QueryParam("clientName") String clientName
    );

    @GET
    @Path("/client")
    List<RoleDTO> getAllClientRoles(
        @QueryParam("realm") String realmName,
        @QueryParam("clientName") String clientName
    );

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

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

    // ==================== Role Assignment ====================

    @POST
    @Path("/assign")
    void assignRoleToUser(RoleAssignmentDTO assignment);

    @POST
    @Path("/revoke")
    void revokeRoleFromUser(RoleAssignmentDTO assignment);

    @GET
    @Path("/user/{userId}")
    List<RoleDTO> getUserRoles(
        @PathParam("userId") String userId,
        @QueryParam("realm") String realmName
    );

    // ==================== Composite Roles ====================

    @GET
    @Path("/composite/{roleName}")
    List<RoleDTO> getCompositeRoles(
        @PathParam("roleName") String roleName,
        @QueryParam("realm") String realmName,
        @QueryParam("typeRole") TypeRole typeRole,
        @QueryParam("clientName") String clientName
    );

    @POST
    @Path("/composite/{roleName}/add")
    void addCompositeRole(
        @PathParam("roleName") String roleName,
        @QueryParam("realm") String realmName,
        @QueryParam("compositeRoleName") String compositeRoleName
    );

    @DELETE
    @Path("/composite/{roleName}/remove")
    void removeCompositeRole(
        @PathParam("roleName") String roleName,
        @QueryParam("realm") String realmName,
        @QueryParam("compositeRoleName") String compositeRoleName
    );
}

