/*-
 * ~~~~~~licensing~~~~~~
 * test-producers
 * ==========
 * Copyright (C) 2020 - 2025 EmDev LLC
 * ==========
 * You may not use this file except in accordance with the License Terms of the Copyright
 * Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
 * rights to the Software and any copies are the property of the Copyright Holder. Unless
 * it is explicitly allowed the Copyright Holder, the User is prohibited from using the
 * Software for commercial purposes to provide services to third parties.
 * 
 * The Copyright Holder hereby declares that the Software is provided on an "AS IS".
 * Under no circumstances does the Copyright Holder guarantee or promise that the
 * Software provided by him will be suitable or not suitable for the specific purposes
 * of the User, that the Software will meet all commercial and personal subjective
 * expectations of the User, that the Software will work properly, without technical
 * errors, quickly and uninterruptedly.
 * 
 * Under no circumstances shall the Copyright Holder or its Affiliates is not liable
 * to the User for any direct or indirect losses of the User, his expenses or actual
 * damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
 * or damage to data, property, etc.
 * ~~~~~~/licensing~~~~~~
 */
package ru.entaxy.platform.core.producer.impl;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import ru.entaxy.platform.base.objects.factory.EntaxyFactory;

public class FieldInfoImpl implements EntaxyFactory.FieldInfo {

	JsonObject jsonOrigin = null;
	
	String name = "";
	String type = "";
	String displayName = "";
	String description = "";
	
	boolean immutable = false;
	boolean required = false;
	Object defaultValue = "";

	boolean conditional = false;
	String condition = null;
	
	boolean isRef = false;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDisplayName() {
		return displayName;
	}
	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public Object getDefaultValue() {
		return defaultValue;
	}
	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}
	public boolean isRequired() {
		return required;
	}
	public void setRequired(boolean isRequired) {
		this.required = isRequired;
	}
	public boolean isImmutable() {
		return immutable;
	}
	public void setImmutable(boolean isImmutable) {
		this.immutable = isImmutable;
	}
	
	public FieldInfoImpl name(String nameValue) {
		this.setName(nameValue);
		return this;
	};
	
	public FieldInfoImpl displayName(String displayNameValue) {
		this.setDisplayName(displayNameValue);
		return this;
	};

	public FieldInfoImpl type(String typeValue) {
		this.setType(typeValue);
		return this;
	};
	
	public FieldInfoImpl defaultValue(String DefaultValueValue) {
		this.setDefaultValue(DefaultValueValue);
		return this;
	};
	
	public FieldInfoImpl description(String descriptionValue) {
		this.setDescription(descriptionValue);
		return this;
	};
	
	public FieldInfoImpl required(boolean requiredValue) {
		this.setRequired(requiredValue);
		return this;
	};
	
	public FieldInfoImpl immutable(boolean immutableValue) {
		this.setImmutable(immutableValue);
		return this;
	}
	
	public boolean isConditional() {
		return conditional;
	}
	public void setConditional(boolean conditional) {
		this.conditional = conditional;
	}
	public String getCondition() {
		return condition;
	}
	public void setCondition(String condition) {
		this.condition = condition;
	}
	public boolean isRef() {
		return isRef;
	}
	public void setRef(boolean isRef) {
		this.isRef = isRef;
	}
	public void setDefaultValue(Object defaultValue) {
		this.defaultValue = defaultValue;
	}
	@Override
	public JsonObject getJsonOrigin() {
		if (jsonOrigin == null) {
			Gson gson = new Gson();
			JsonElement result = gson.toJsonTree(this);
			if (result.isJsonObject()) {
				this.jsonOrigin = result.getAsJsonObject();
				// remove origin itself
			}
		}
			
		return this.jsonOrigin;
	}
	public void setJsonOrigin(JsonObject jsonOrigin) {
		this.jsonOrigin = jsonOrigin;
	};
	
}
