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

import dev.lions.user.manager.client.filter.AuthHeaderFactory;
import dev.lions.user.manager.dto.user.UserDTO;
import dev.lions.user.manager.dto.user.UserSearchResultDTO;
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/users")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface UserRestClient {

        @GET
        UserSearchResultDTO searchUsers(
                        @QueryParam("realm") String realmName,
                        @QueryParam("search") String searchTerm,
                        @QueryParam("username") String username,
                        @QueryParam("email") String email,
                        @QueryParam("prenom") String prenom,
                        @QueryParam("nom") String nom,
                        @QueryParam("enabled") Boolean enabled,
                        @QueryParam("page") int page,
                        @QueryParam("pageSize") int pageSize);

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

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

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

        @DELETE
        @Path("/{id}")
        void deleteUser(@PathParam("id") String id, @QueryParam("realm") String realmName,
                        @QueryParam("hard") boolean hardDelete);

        @PUT
        @Path("/{id}/activate")
        void activateUser(@PathParam("id") String id, @QueryParam("realm") String realmName);

        @PUT
        @Path("/{id}/deactivate")
        void deactivateUser(@PathParam("id") String id, @QueryParam("realm") String realmName,
                        @QueryParam("reason") String reason);

        @POST
        @Path("/{id}/reset-password")
        void resetPassword(@PathParam("id") String id, @QueryParam("realm") String realmName,
                        PasswordResetRequest request);

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

        @GET
        @Path("/export/csv")
        @Produces(MediaType.TEXT_PLAIN)
        String exportUsersToCSV(@QueryParam("realm") String realmName);

        // Inner class for password reset request DTO
        class PasswordResetRequest {
                public String password;
                public boolean temporary;
        }
}
