package net.geedge.api.util;

import net.geedge.common.T;

import java.util.LinkedList;
import java.util.List;

public class PythonCommandBuilder {

    private final String pythonPath;
    private final List<String> command;

    public PythonCommandBuilder(String pythonPath) {
        this.pythonPath = pythonPath;
        this.command = new LinkedList<>();
        this.command.add(pythonPath);
    }

    public static PythonCommandBuilder builder() {
        return new PythonCommandBuilder("python");
    }

    public static PythonCommandBuilder builder(String pythonPath) {
        return new PythonCommandBuilder(pythonPath);
    }
    public PythonCommandBuilder buildRunAirScript(String launcher, String path, String jobId, String packageName, String serial) {
        this.command.add(launcher);
        this.command.add(path);
        this.command.add("--device");
        this.command.add(T.StrUtil.concat(true,"Android://127.0.0.1:5037/", serial));
        this.command.add("--job_id");
        this.command.add(jobId);
        this.command.add("--job_path");
        this.command.add(path);
        this.command.add("--package_name");
        this.command.add(packageName);
        return this;
    }

    public PythonCommandBuilder buildRunPythonScript(String path, String jobId, String packageName, String serial) {
        this.command.add(path);
        this.command.add("--device");
        this.command.add(T.StrUtil.concat(true,"Android://127.0.0.1:5037/", serial));
        this.command.add("--serial");
        this.command.add(serial);
        this.command.add("--job_id");
        this.command.add(jobId);
        this.command.add("--job_path");
        this.command.add(path);
        this.command.add("--package_name");
        this.command.add(packageName);
        return this;
    }

    public PythonCommandBuilder buildCreateVenv(String path) {
        this.command.add("-m");
        this.command.add("venv");
        this.command.add(path);
        this.command.add("--system-site-packages");
        return this;
    }

    public PythonCommandBuilder buildUpgradePip() {
        this.command.add("install");
        this.command.add("--upgrade");
        this.command.add("pip");
        return this;
    }

    public PythonCommandBuilder buildInstallRequirements(String path) {
        this.command.add("install");
        this.command.add("-r");
        this.command.add(path);
        return this;
    }

    public List<String> build() {
        return this.command;
    }
}