package it.enea.cruise.dto;

import java.util.HashMap;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreType;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;


@Getter
@Setter
@ToString
@NoArgsConstructor
@JsonIgnoreType
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MetadataDTO {
	
	
	@JsonProperty("name")
	private String columnName;
	
	@JsonProperty("descriptionLong") 
	String descriptionLong;
	
	@JsonProperty("descriptionShort") 
	String descriptionShort;

	@JsonProperty("default")
	private String columnDefault;
	
	@JsonProperty("type")
	private String dataType;
	
	private String example;
	
	@JsonIgnore
	private String isIdentity;
	
	private Boolean required;
	
	private String value;
	
	@JsonIgnore
	private String language;
		
	private String target;
	
	private List<HashMap<String, Object>> options;
	
	private List<HashMap<String, Object>> multipleOptions;
	
	private Boolean columnProtected;
	
//	public void setColumnComment(String cComment) {
//		columnComment = getDescription(cComment, language);
//		example = getExample(cComment);
//	};
//	
//	
//	public String getDescription(String cComment, String language) {
//		if (cComment != null) {
//			log.info("working with: " + cComment);
//			String[] result = cComment.contains("|") ? cComment.split(" \\| ") : null;
//			if (result != null) {
//				if (language.contains("it")) {
//					return (result[2] + " | " + result[3]);
//				} else {
//					if (result.length > 2) {
//						return (result[0] + " | " + result[1]);
//					} else
//						return (result[0] + " | " + result[1]);
//				}
//			} else
//				return cComment;
//		}	else return "";
//	}
//	
//	public String getExample (String cComment) {
//		String ex = cComment != null && cComment.contains("ex:") ? cComment.split(" \\|.+ex: ")[1] : "";
//		
//		return ex;
//	}

	public void setIs_Nullable (String isNullable) {
		required = (isNullable != null && isNullable.contains("NO")) ? true : false; 
	}

	
}