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

import dev.lions.user.manager.client.filter.AuthHeaderFactory;
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;

import java.util.List;
import java.util.Map;

/**
 * REST Client pour le service de synchronisation
 */
@Path("/api/sync")
@RegisterRestClient(configKey = "lions-user-manager-api")
@RegisterClientHeaders(AuthHeaderFactory.class)
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface SyncServiceClient {

    @GET
    @Path("/health")
    HealthCheckResponse checkHealth();

    @GET
    @Path("/health/detailed")
    Map<String, Object> getDetailedHealthStatus();

    @POST
    @Path("/users/{realmName}")
    SyncUsersResponse syncUsers(@PathParam("realmName") String realmName);

    @POST
    @Path("/roles/realm/{realmName}")
    SyncRolesResponse syncRealmRoles(@PathParam("realmName") String realmName);

    @POST
    @Path("/roles/client/{clientId}/{realmName}")
    SyncRolesResponse syncClientRoles(
        @PathParam("clientId") String clientId,
        @PathParam("realmName") String realmName
    );

    @POST
    @Path("/all/{realmName}")
    Map<String, Object> syncAll(@PathParam("realmName") String realmName);

    @GET
    @Path("/check/realm/{realmName}")
    ExistsCheckResponse checkRealmExists(@PathParam("realmName") String realmName);

    @GET
    @Path("/check/user/{userId}")
    ExistsCheckResponse checkUserExists(
        @PathParam("userId") String userId,
        @QueryParam("realm") String realmName
    );

    // ==================== DTOs de réponse ====================

    class SyncUsersResponse {
        public int count;
        public List<dev.lions.user.manager.dto.user.UserDTO> users;
    }

    class SyncRolesResponse {
        public int count;
        public List<dev.lions.user.manager.dto.role.RoleDTO> roles;
    }

    class HealthCheckResponse {
        public boolean healthy;
        public String message;
    }

    class ExistsCheckResponse {
        public boolean exists;
        public String resourceType;
        public String resourceId;
    }
}

