package demo.routing;

import com.sun.net.httpserver.HttpServer;

import demo.examples.redirect.AuthenticationRedirectBizum;
import demo.examples.redirect.AuthenticationRedirectCard;
import demo.examples.redirect.AuthorisationRedirectBizum;
import demo.examples.redirect.AuthorisationRedirectCard;
import demo.examples.redirect.PreauthorisationRedirectCard;
import demo.examples.redirect.RefundRedirectBizum;
import demo.examples.redirect.RefundRedirectCard;
import demo.examples.rest.AuthenticationRestCard;
import demo.examples.rest.AuthorisationRestCard;
import demo.examples.rest.ChallengeResponse;
import demo.examples.rest.ReceiveNotification;
import demo.examples.rest.RefundRestBizum;
import demo.examples.rest.RefundRestCard;
import demo.server.Server;

public class Routing {
    public static void routing(HttpServer server) {
    	/*** Healthcheck ***/
		server.createContext("/healthcheck", Server::healtcheck);
		
        /*** Frontend ***/
		server.createContext("/", exchange -> {
			Server.serverRedirect(exchange, "/frontend/index.html", 302);
		});

		server.createContext("/frontend", Server::handleStatic);
		
		/*** Backend ***/
		// Redirect
		server.createContext("/backend/authorisation/card/redirect", AuthorisationRedirectCard::authorisationRedirectExample);
		server.createContext("/backend/authorisation/bizum/redirect", AuthorisationRedirectBizum::authorisationRedirectBizumExample);
		
		server.createContext("/backend/authentication/card/redirect", AuthenticationRedirectCard::authenticationRedirectExample);
		server.createContext("/backend/preauthorisation/card/redirect", PreauthorisationRedirectCard::preauthorisationRedirectExample);
		server.createContext("/backend/authentication/bizum/redirect", AuthenticationRedirectBizum::authenticationRedirectBizumExample);
		
		server.createContext("/backend/authenticationConfirmation/card/redirect", AuthenticationRedirectCard::authenticationConfirmationRedirectExample);
		server.createContext("/backend/preauthorisationConfirmation/card/redirect", PreauthorisationRedirectCard::preauthorisationConfirmationRedirectExample);
		server.createContext("/backend/authenticationConfirmation/bizum/redirect", AuthenticationRedirectBizum::authenticationConfirmationRedirectBizumExample);
		
		server.createContext("/backend/refund/card/redirect", RefundRedirectCard::refundRedirectExample);
		server.createContext("/backend/refund/bizum/redirect", RefundRedirectBizum::refundRedirectBizumExample);

		// Rest
		server.createContext("/backend/authorisation/card/rest", AuthorisationRestCard::authorisationRestExample);
		server.createContext("/backend/authentication/card/rest", AuthenticationRestCard::authenticationRestExample);
		server.createContext("/backend/authorisation/card/rest/dcc", AuthorisationRestCard::authorisationDccRestExample);

		server.createContext("/backend/challenge-response", ChallengeResponse::challengeResponseExample);
		
		server.createContext("/backend/authenticationConfirmation/card/rest", AuthenticationRestCard::authenticationConfirmationRestExample);
		
		server.createContext("/backend/refund/bizum/rest", RefundRestBizum::refundRestExample);
		server.createContext("/backend/refund/card/rest", RefundRestCard::refundRestExample);
		
		// Notifications
		server.createContext("/backend/card/notification", ReceiveNotification::handleCard);
		server.createContext("/backend/bizum/notification", ReceiveNotification::handleBizum);
    }
}
