package com.github.catatafishen.agentbridge.psi.tools.quality;

import com.github.catatafishen.agentbridge.psi.QodanaAnalyzer;
import com.google.gson.JsonObject;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

/**
 * Runs Qodana static analysis and returns findings.
 */
public final class RunQodanaTool extends QualityTool {

    private final QodanaAnalyzer qodanaAnalyzer;

    public RunQodanaTool(Project project, QodanaAnalyzer qodanaAnalyzer) {
        super(project);
        this.qodanaAnalyzer = qodanaAnalyzer;
    }

    @Override
    public @NotNull String id() {
        return "run_qodana";
    }

    @Override
    public @NotNull String displayName() {
        return "Run Qodana";
    }

    @Override
    public @NotNull String description() {
        return "Run Qodana static analysis and return findings";
    }

    @Override
    public @NotNull Kind kind() {
        return Kind.READ;
    }

    @Override
    public boolean isReadOnly() {
        return true;
    }

    @Override
    public @NotNull JsonObject inputSchema() {
        return schema(
            Param.optional(PARAM_LIMIT, TYPE_INTEGER, "Maximum number of problems to return (default: 100)")
        );
    }

    @Override
    public @NotNull String execute(@NotNull JsonObject args) throws Exception {
        return qodanaAnalyzer.runQodana(args);
    }
}
