package divconq.db.update;

import divconq.db.IDatabaseManager;
import divconq.struct.FieldStruct;
import divconq.struct.RecordStruct;
import divconq.struct.Struct;

/**
 * Use this field to update StaticSalar structures in dcDatabase.
 * 
 * @author Andy
 *
 */
public class ScalarField extends DbField {
	/**
	 * @param name of field
	 * @param value of field
	 * @param tags meta data for the field (alphanumeric and ':' are allowed in tag)
	 */
	public ScalarField(String name, Object value, FieldTags tags) {
		super(name, value, tags);
	}
	
	/**
	 * @param name of field
	 * @param value of field
	 */
	public ScalarField(String name, Object value) {
		super(name, value, null);
	}
	
	/**
	 * Mark a field as Retired
	 * 
	 * @param name of field
	 * @param tags meta data for the field (alphanumeric and ':' are allowed in tag)
	 */
	public ScalarField(String name, FieldTags tags) {
		super(name, tags);
	}
	
	/**
	 * Mark a field as Retired
	 */
	public ScalarField(String name) {
		super(name, null);
	}

	/* (non-Javadoc)
	 * @see divconq.db.update.DbField#convert(divconq.struct.RecordStruct, divconq.db.IDatabaseManager)
	 */
	@Override
	public Struct convert(RecordStruct fields, IDatabaseManager dbm) {
		RecordStruct ret = new RecordStruct( 
				new FieldStruct("Data", dbm.convertValue(this.value).getResult())
		);
		
		if (this.tags != null)
			ret.setField("Tags", this.tags);
		
		if (this.retired)
			ret.setField("Retired", true);
		
		return ret;
	}
}
