package fr.doap.qodoclient;

import io.quarkus.security.*;
import io.quarkus.security.identity.*;
import jakarta.annotation.security.*;
import jakarta.inject.*;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.*;
import org.eclipse.microprofile.jwt.*;
import org.eclipse.microprofile.rest.client.inject.*;

@Path("/protected")
@Authenticated
public class GreetingResource {
	@Inject
	SecurityIdentity mIdentity;
	
//	@IdToken
	@Inject
	JsonWebToken mPrincipal;
	
	@Inject
	@RestClient
	RestClientWithTokenPropagationFilter mClient;

	@RolesAllowed("user11")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String hello() {
//        return "Protected by OIDC: "+mIdentity.getPrincipal();
		
		String lR = mClient.getOIDC();
		
		System.out.println("Roles: "+mIdentity.getRoles());
		System.out.println("Credentials: "+mIdentity.getCredentials());
		System.out.println("JWT Roles: "+mPrincipal.getClaim("roles"));
		return "Frontend asked the backend --> "+lR.toString();
    }
}
