package com.r11.tools.controller;

import com.r11.tools.controller.internal.GlobalControllerManifest;
import com.r11.tools.controller.internal.HandlerType;
import com.r11.tools.controller.internal.RestController;
import com.r11.tools.controller.internal.ScopedControllerManifest;
import com.r11.tools.xml.Saxon;
import org.apache.logging.log4j.Logger;
import spark.Request;
import spark.Response;

@GlobalControllerManifest
public class ProcessorInfoController implements RestController {

    private final Logger logger;

    public ProcessorInfoController(Logger logger) {
        this.logger = logger;
    }

    /**
     * Handler that returns processor version
     */
    @ScopedControllerManifest(method = HandlerType.GET, path = "/procinfo")
    public void processorInfo(Request request, Response response) {
        try {
            response.header("processor", "Saxon " + Saxon.getVersion() + " over s9api");
            response.body(Saxon.getVersion());
        } catch (Exception ex) {
            this.logger.error("Error on retrieving engine version. " + ex);
            response.body(ex.getMessage());
        }
    }
}
