package ai.testers;

public final class Config {
    public String apiKey;
    public String baseUrl = "https://api.testers.ai";
    public boolean enabled = true;
    public int timeoutMs = 15_000;
    public int maxRetries = 3;
    public int maxRetryWaitMs = 5_000;
    public boolean strict = false;
    public String sink = "framework";      // comma-separated: framework,disk,return
    public String sinkDir = "./testersai-results";
    public String logFormat = "json";      // json|junit|tap|text
    public boolean quiet = false;          // when true, suppress SDK-level log output

    public static Config fromEnv() {
        Config c = new Config();
        c.apiKey = System.getenv("TESTERSAI_API_KEY");
        c.baseUrl = envOr("TESTERSAI_BASE_URL", c.baseUrl);
        c.enabled = envBool("TESTERSAI_ENABLED", c.enabled);
        c.timeoutMs = envInt("TESTERSAI_TIMEOUT_MS", c.timeoutMs);
        c.maxRetries = envInt("TESTERSAI_MAX_RETRIES", c.maxRetries);
        c.maxRetryWaitMs = envInt("TESTERSAI_MAX_RETRY_WAIT_MS", c.maxRetryWaitMs);
        c.strict = envBool("TESTERSAI_STRICT", c.strict);
        c.sink = envOr("TESTERSAI_SINK", c.sink);
        c.sinkDir = envOr("TESTERSAI_SINK_DIR", c.sinkDir);
        c.logFormat = envOr("TESTERSAI_LOG_FORMAT", c.logFormat);
        c.quiet = envBool("TESTERSAI_QUIET", c.quiet);
        return c;
    }

    private static String envOr(String k, String d) { String v = System.getenv(k); return v == null ? d : v; }
    private static int envInt(String k, int d) { try { return Integer.parseInt(System.getenv(k)); } catch (Exception e) { return d; } }
    private static boolean envBool(String k, boolean d) {
        String v = System.getenv(k);
        return v == null ? d : v.matches("(?i)1|true|yes|on");
    }
}
