package lc.esp.engine;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.PathItem;
import io.swagger.v3.oas.models.Paths;
import io.swagger.v3.parser.OpenAPIV3Parser;
import lc.mecha.log.MechaLogger;
import lc.mecha.log.MechaLoggerFactory;
import org.apache.commons.io.IOUtils;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.Map;

/**
 * This class processes an OpenAPI 3.0 specification to organize a parser framework for the purposes of processing
 * HTTP requests.
 *
 * @author Alex Leigh
 * @since mk20 (TOKYO PROTOCOL)
 */
public class StubGenerator {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(StubGenerator.class);

    public static void main(String[] args) throws IOException {
        new StubGenerator();
    }

    public StubGenerator() throws IOException {
        String currentDir = System.getProperty("user.dir");
        logger.info("Current dir using System:" + currentDir);

        InputStream inputStream = new FileInputStream("lc-esp-eo-svc/eo.yaml");
        StringWriter writer = new StringWriter();
        IOUtils.copy(inputStream, writer);

        OpenAPI openApi = new OpenAPIV3Parser().readContents(writer.toString()).getOpenAPI();
        // logger.info("Parsed: {}", openApi);

        // logger.info("Paths: {}", openApi.getPaths());
        Paths paths = openApi.getPaths();
        for (Map.Entry<String, PathItem> entry : paths.entrySet()) {
            logger.info("Path: {}", entry.getKey());
        }
    }
}
