package epson.print;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;

public class EPPrinterInfo implements Serializable {
    static final long serialVersionUID = -4712510101292698959L;
    public String printerAccessKey = "";
    public String printerEmailAddress = "";
    public String printerID = "";
    public String printerIP = "";
    public int printerLocation = 0;
    public String printerName = "";
    public String printerSerialNo = "";
    public String scannerID = "";
    public String userDefName = "";

    public void writeJSON(FileOutputStream fileOutputStream) throws JSONException, IOException {
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("printerName", this.printerName);
        jSONObject.put("printerID", this.printerID);
        jSONObject.put("printerIP", this.printerIP);
        String str = this.printerSerialNo;
        if (str == null) {
            str = "";
        }
        jSONObject.put("printerSerialNo", str);
        jSONObject.put("printerLocation", this.printerLocation);
        jSONObject.put("printerEmailAddress", this.printerEmailAddress);
        jSONObject.put("printerAccessKey", this.printerAccessKey);
        jSONObject.put("userDefName", this.userDefName);
        jSONObject.put("scannerID", this.scannerID);
        fileOutputStream.write(jSONObject.toString().getBytes());
    }

    public void readJSON(FileInputStream fileInputStream) throws JSONException, IOException {
        byte[] bArr = new byte[fileInputStream.available()];
        fileInputStream.read(bArr);
        JSONObject jSONObject = new JSONObject(new String(bArr));
        this.printerName = jSONObject.getString("printerName");
        this.printerID = jSONObject.getString("printerID");
        this.printerIP = jSONObject.getString("printerIP");
        this.printerSerialNo = jSONObject.getString("printerSerialNo");
        this.printerLocation = jSONObject.getInt("printerLocation");
        this.printerEmailAddress = jSONObject.getString("printerEmailAddress");
        this.printerAccessKey = jSONObject.getString("printerAccessKey");
        this.userDefName = jSONObject.getString("userDefName");
        try {
            this.scannerID = jSONObject.getString("scannerID");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
