package eu.dnetlib.rmi.objects.is;

import java.util.Map;

import javax.xml.bind.annotation.XmlRootElement;

import com.google.common.collect.Maps;

import eu.dnetlib.enabling.annotations.DnetResourceHelper;
import eu.dnetlib.enabling.utils.DnetAnnotationUtils;
import eu.dnetlib.rmi.soap.exceptions.InformationServiceException;

@XmlRootElement
public class DnetDataStructure extends DnetResource {

	private String code;
	private String name;
	private String description;
	private String type;
	private String serviceId;
	private String content;
	private Map<String, String> properties = Maps.newHashMap();

	public String getCode() {
		return code;
	}

	public void setCode(final String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(final String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(final String description) {
		this.description = description;
	}

	public String getType() {
		return type;
	}

	public void setType(final String type) {
		this.type = type;
	}

	public String getServiceId() {
		return serviceId;
	}

	public void setServiceId(final String serviceId) {
		this.serviceId = serviceId;
	}

	public String getContent() {
		return content;
	}

	public void setContent(final String content) {
		this.content = content;
	}

	public <T> T getContentAsObject(final Class<T> clazz) throws InformationServiceException {
		return DnetResourceHelper.convertToObject(content, clazz);
	}

	public void setContentFromObject(final Object o) throws InformationServiceException {
		this.content = DnetResourceHelper.convertToString(o);
		this.properties = DnetAnnotationUtils.getIndexedFields(o);
	}

	@Override
	public String toString() {
		return String.format("[ id = %s, type = %s ]", getId(), type);
	}

	public Map<String, String> getProperties() {
		return properties;
	}

	public void setProperties(final Map<String, String> properties) {
		this.properties = properties;
	}

}
