/*
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap.Config;
import android.util.Base64;
import java.nio.ByteBuffer;
import org.json.JSONObject;
*/

import {FieldRect} from './FieldRect';

export class DocumentReaderGraphicField {
    constructor() {
        this.sourceType = null;//int
        this.fieldType = null;//int
        this.fieldName = null;//String
        this.lightType = -1;//int
        this.lightName = null;//String
        this.fieldRect = new FieldRect();//FieldRect
        this.imgBytes = [];//byte[]
        this.base64Value = null;//String
        this.pageIndex = null;//int
        this.width = null;
        this.height = null;
    }

    value() {
        return this.base64Value;//Bitmap converted to base64 string(int java library it's Bitmap)
    }

    setImageData(val, width, height) {
        this.imgBytes = val;
        this.width = width;
        this.height = height;
    }
/*
    static fromJson(json) {
        if (json != null && !json.isEmpty()) {
            try {
                object = new JSONObject(json);
                return fromJson(object);
            } catch (var2) {
                var2.printStackTrace();
            }
        }

        return null;
    }
*/
    static fromJson(jsonObject) {
        if (jsonObject != null) {
            var field = new DocumentReaderGraphicField();
            field.sourceType = jsonObject["sourceType"];
            field.fieldType = jsonObject["fieldType"];
            field.fieldName = jsonObject["fieldName"];
            field.lightType = jsonObject["lightType"];
            field.lightName = jsonObject["lightName"];
            field.fieldRect = FieldRect.fromJson(jsonObject["fieldRect"]);
            //field.imgBytes=atob(jsonObject["value"], 3);  DECODE 64
            field.base64Value = jsonObject["value"];
            field.width = jsonObject["width"];
            field.height = jsonObject["height"];
            field.pageIndex = jsonObject["pageIndex"];
            return field;
        }

        return null;
    }
    
    log(tab){
        console.log(tab + "{");
        console.log(tab + "    sourceType: " + this.sourceType);
        console.log(tab + "    fieldType: " + this.fieldType);
        console.log(tab + "    fieldName: " + this.fieldName);
        console.log(tab + "    lightType: " + this.lightType);
        console.log(tab + "    lightName: " + this.lightName);
        console.log(tab + "    fieldRect: {");
        console.log(tab + "        left: " + this.fieldRect.left);
        console.log(tab + "        right: " + this.fieldRect.right);
        console.log(tab + "        top: " + this.fieldRect.top);
        console.log(tab + "        bottom: " + this.fieldRect.bottom);
        console.log(tab + "    }");
        console.log(tab + "    imgBytes: " + this.imgBytes);
        console.log(tab + "    base64Value: image");
        console.log(tab + "    pageIndex: " + this.pageIndex);
        console.log(tab + "    width: " + this.width);
        console.log(tab + "    height: " + this.height);
        console.log(tab + "}");
    }
}
