package dev.lions.unionflow.server.client;

import dev.lions.user.manager.dto.user.UserDTO;
import dev.lions.user.manager.dto.user.UserSearchCriteriaDTO;
import dev.lions.user.manager.dto.user.UserSearchResultDTO;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

/**
 * REST Client admin pour le service de gestion des utilisateurs Keycloak
 * via lions-user-manager API.
 *
 * <p>Utilise {@link AdminServiceTokenHeadersFactory} pour injecter le token
 * du service account "admin-service" (client credentials grant) de façon
 * explicite, sans ambiguïté avec les autres clients partageant le même configKey.
 */
@Path("/api/users")
@RegisterRestClient(configKey = "lions-user-manager-api")
@RegisterClientHeaders(AdminServiceTokenHeadersFactory.class)
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface AdminUserServiceClient {

    @POST
    @Path("/search")
    UserSearchResultDTO searchUsers(UserSearchCriteriaDTO criteria);

    @GET
    @Path("/{userId}")
    UserDTO getUserById(
            @PathParam("userId") String userId,
            @QueryParam("realm") String realmName);

    @POST
    UserDTO createUser(
            UserDTO user,
            @QueryParam("realm") String realmName);

    @PUT
    @Path("/{userId}")
    UserDTO updateUser(
            @PathParam("userId") String userId,
            UserDTO user,
            @QueryParam("realm") String realmName);

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

    @POST
    @Path("/{userId}/send-verification-email")
    void sendVerificationEmail(
            @PathParam("userId") String userId,
            @QueryParam("realm") String realmName);

    @POST
    @Path("/{userId}/reset-password")
    void resetPassword(
            @PathParam("userId") String userId,
            @QueryParam("realm") String realmName,
            dev.lions.user.manager.dto.user.PasswordResetRequestDTO request);
}
