package cc.winboll.studio.webpagesources.models;

/**
 * @Author ZhanGSKen@QQ.COM
 * @Date 2024/08/26 15:43:22
 * @Describe 验证信息数据类
 */
import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.libappbase.BaseBean;
import java.io.IOException;

public class AuthenticationBean extends BaseBean {

    public static final String TAG = "AuthenticationBean";

    // 主机名
    String host;
    // 认证区域
    String realm;
    // 用户名
    String userName;
    // 密码
    String password;

    public AuthenticationBean(String host, String realm, String userName, String password) {
        this.host = host;
        this.realm = realm;
        this.userName = userName;
        this.password = password;
    }
    
    public AuthenticationBean(AuthenticationBean bean) {
        this.host = bean.getHost();
        this.realm = bean.getRealm();
        this.userName = bean.getUserName();
        this.password = bean.getPassword();
    }

    public AuthenticationBean() {
        this.host = "";
        this.realm = "";
        this.userName = "";
        this.password = "";
    }

    public void setRealm(String realm) {
        this.realm = realm;
    }

    public String getRealm() {
        return realm;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getHost() {
        return host;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserName() {
        return userName;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPassword() {
        return password;
    }

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

    @Override
    public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
        super.writeThisToJsonWriter(jsonWriter);
        AuthenticationBean bean = this;
        jsonWriter.name("host").value(bean.getHost());
        jsonWriter.name("realm").value(bean.getRealm());
        jsonWriter.name("userName").value(bean.getUserName());
        jsonWriter.name("password").value(bean.getPassword());
    }

    @Override
    public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
        if (super.initObjectsFromJsonReader(jsonReader, name)) { return true; } else {
            if (name.equals("host")) {
                setHost(jsonReader.nextString());
            } else if (name.equals("realm")) {
                setRealm(jsonReader.nextString());
            } else if (name.equals("userName")) {
                setUserName(jsonReader.nextString());
            } else if (name.equals("password")) {
                setPassword(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;
    }
}
