package riomhaire.lti.core.infrastructure.api.tool;

import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import riomhaire.lti.core.infrastructure.api.Endpoint;
import riomhaire.lti.core.model.LTIMessage;
import riomhaire.lti.core.model.LTIMessageType;

import java.util.Map;

@RestController
public class JwksEndpoint  extends Endpoint {

    @RequestMapping(path = "/jwks")
    public ModelAndView oidc(@RequestParam Map<String, String> queryParams, @RequestHeader Map<String, Object> headers) {

        var message = LTIMessage.builder()
                .messageType(LTIMessageType.BuildJWKSResponse.name())
                .metadata(headers)
                .queryParams(queryParams)
                .build();
        return getDispatcher().dispatch(getRegistry(), message);
    }
}
