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 com.r11.tools.xml.XmlEngine;
import org.apache.logging.log4j.Logger;
import spark.Request;
import spark.Response;

@GlobalControllerManifest
public class ProcessorInfoController implements RestController {

    private final Logger logger;
    private final XmlEngine saxon;
    private final XmlEngine xalan;

    public ProcessorInfoController(Logger logger, XmlEngine saxon, XmlEngine xalan) {
        this.logger = logger;
        this.saxon = saxon;
        this.xalan = xalan;
    }

    /**
     * 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());
        }
    }
}
