package lc.jira;

import lc.mecha.log.MechaLogger;
import lc.mecha.log.MechaLoggerFactory;
import lc.mecha.util.UniversalJob;
import org.apache.commons.lang.StringUtils;

import java.io.IOException;
import java.net.URISyntaxException;

public class JiraApp {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(JiraApp.class);
    public static final String ENV_USERNAME = "LC_JIRA_USERNAME";
    public static final String ENV_PASSWORD = "LC_JIRA_PASSWORD";
    public static final String ENV_URL = "LC_JIRA_URL";

    public static void main(String[] args) throws IOException, URISyntaxException {
        var username = System.getenv(ENV_USERNAME);
        var password = System.getenv(ENV_PASSWORD);

        if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
            logger.error("LC_JIRA_USERNAME & LC_JIRA_PASSWORD environment variables must be set.");
            System.exit(UniversalJob.RET_BADARGS);
        }

        var baseUrl = System.getenv(ENV_URL);
        if (StringUtils.isEmpty(baseUrl)) {
            logger.error("LC_JIRA_URL must be set.");
            System.exit(UniversalJob.RET_BADARGS);
        }

        var jira = new Jira(baseUrl, username, password);
        jira.search();
    }
}
