package com.bayer.edam.migration.adam;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.bayer.edam.migration.Definitions;

public class WriteRecord {
	
	private static final Logger log = LoggerFactory.getLogger(WriteRecord.class);
	
	public static class Classification {
		public String id;
		public Integer sortIndex;
		
		public Classification(String id, Integer sortIndex) {
			this.id = id;
			this.sortIndex = sortIndex;
		}
	}
	
	public static class Classifications {
		public List<Classification> addOrUpdate = new ArrayList<Classification>();
	}
	
	public static class LocalizedValue {
		public String languageId = Definitions.defaultLanguage;
		public String value;
		public List<String> values = new ArrayList<String>();
		
		public LocalizedValue(String value) {
			this.value = value;
		}
		
		public LocalizedValue(List<String> values) {
			this.values = values;
		}
	}
	
	public static class Field {
		public String id;
		public List<LocalizedValue> localizedValues = new ArrayList<LocalizedValue>();
		
		public Field(String id) {
			this.id = id;
		}
		
		public Field() {
		}
	}
	
	public static class Fields {
		public List<Field> addOrUpdate = new ArrayList<Field>();
	}
	
	public String contentType = "Record";
	public Classifications classifications = new Classifications();
	public Fields fields = new Fields();
	
	public void add(Classification classification) {
		classifications.addOrUpdate.add(classification);
	}
	
	public void add(Field field) {
		fields.addOrUpdate.add(field);
	}
	
	public void addClassification(Classification classification) {
		add(classification);
	}
	
	public void addClassification(String name) {
		Classification classification = Definitions.classifications.get(name);
		
		if (classification == null) {
			log.error("Could not find classification for '" + name + "'");
		}
		else {
			log.debug("Adding classification " + name);
			add(classification);
		}
	}
	
	public void addField(String name, String value) {
		fields.addOrUpdate.add(Definitions.createSingleValueField(name, value));
	}
	
	public void addField(String name, List<String> values) {
		fields.addOrUpdate.add(Definitions.createMultiValueField(name, values));
	}
	
}
