package cc.winboll.studio.winboll.models;

import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.libappbase.BaseBean;
import java.io.IOException;

/**
 * @Author 豆包&ZhanGSKen<zhangsken@qq.com>
 * @Date 2026/04/30 10:47
 */
public class TermuxButtonModel extends BaseBean {

    public static final String TAG = "TermuxButtonModel";

    String buttonName;
    String exeCommand;
    String workDir;

    public TermuxButtonModel() {
        this.buttonName = "";
        this.exeCommand = "";
        this.workDir = "";
    }

	public void setButtonName(String buttonName) {
		this.buttonName = buttonName;
	}

	public String getButtonName() {
		return buttonName;
	}

	public void setExeCommand(String exeCommand) {
		this.exeCommand = exeCommand;
	}

	public String getExeCommand() {
		return exeCommand;
	}

	public void setWorkDir(String workDir) {
		this.workDir = workDir;
	}

	public String getWorkDir() {
		return workDir;
	}

    @Override
    public String getName() {
        return UserInfoModel.class.getName();
    }

    @Override
    public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
        super.writeThisToJsonWriter(jsonWriter);
        jsonWriter.name("buttonName").value(getButtonName());
        jsonWriter.name("exeCommand").value(getExeCommand());
        jsonWriter.name("workDir").value(getWorkDir());
    }

    @Override
    public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
        if (super.initObjectsFromJsonReader(jsonReader, name)) { return true; } else {
            if (name.equals("buttonName")) {
                setButtonName(jsonReader.nextString());
            } else if (name.equals("exeCommand")) {
                setExeCommand(jsonReader.nextString());
            } else if (name.equals("workDir")) {
                setWorkDir(jsonReader.nextString());
            } else {
                return false;
            }
        }
        return true;
    }

    @Override
    public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
        jsonReader.beginObject();
        while (jsonReader.hasNext()) {
            String name = jsonReader.nextName();
            if (!initObjectsFromJsonReader(jsonReader, name)) {
                jsonReader.skipValue();
            }
        }
        // 结束 JSON 对象
        jsonReader.endObject();
        return this;
    }
}
