package com.ericsson.ims.mtas.xdms.aggregated.service.document;

import java.math.BigInteger;

import javax.xml.bind.JAXBElement;

import org.slf4j.LoggerFactory;

import com.ericsson.ims.mtas.xdms.cai3g.document.Cai3gDocument;
import com.ericsson.ims.mtas.xdms.cai3g.document.ICai3gDocument;
import com.ericsson.ims.mtas.xdms.communication.diversion.document.CommunicationDiversionDocument;
import com.ericsson.ims.mtas.xdms.communication.diversion.document.ICommunicationDiversionDocument;
import com.ericsson.ims.mtas.xdms.schema.cai3g.Create;
import com.ericsson.ims.mtas.xdms.schema.cai3g.Delete;
import com.ericsson.ims.mtas.xdms.schema.cai3g.Get;
import com.ericsson.ims.mtas.xdms.schema.cai3g.Set;
import com.ericsson.ims.mtas.xdms.schema.communication.diversion.CommunicationDiversionType;
import com.ericsson.ims.mtas.xdms.schema.communication.diversion.CreateMMTel;
import com.ericsson.ims.mtas.xdms.schema.communication.diversion.SetMMTel;

public class AggregatedServiceDocument implements IAggregatedServiceDocument
{
	public static org.slf4j.Logger logger = LoggerFactory.getLogger(AggregatedServiceDocument.class);

	/* always a root document */
	private ICai3gDocument cai3gDocument;

	/* communication diversion document */
	private ICommunicationDiversionDocument diversionDocument;

	public AggregatedServiceDocument()
	{
		cai3gDocument = new Cai3gDocument();
		diversionDocument = new CommunicationDiversionDocument();
	}

	@Override
	public Set createSet(String moType, String id)
	{
		logger.debug("creating Set aggregated service document");

		Set set = diversionDocument.createSet(moType, id);

		SetMMTel mmtel = diversionDocument.getFactory().createSetMMTel();

		mmtel.setPublicIdentityAttribute(id);

		mmtel.setConcurrencyControl(diversionDocument.getFactory().createSetMMTelConcurrencyControl(
				BigInteger.valueOf(89988)));

		mmtel.setCommunicationDiversion(diversionDocument.createDefault());

		Set.MOAttributes moAt = cai3gDocument.getFactory().createSetMOAttributes();

		moAt.setSetMODefinition(cai3gDocument.getFactory().createSetMODefinition(mmtel));

		set.setMOAttributes(cai3gDocument.getFactory().createSetMOAttributes(moAt));

		return set;
	}

	@Override
	public Create createCreate(String moType, String id)
	{
		logger.debug("creating aggregated service document");

		Create create = diversionDocument.createCreate(moType, id);

		CreateMMTel mmtel = diversionDocument.getFactory().createCreateMMTel();

		mmtel.setPublicIdentityElement(diversionDocument.getFactory().createPublicId(id));

		mmtel.setPublicIdentityAttribute(id);

		return create;
	}

	@Override
	public Get createGet(String moType, String id)
	{
		logger.debug("creating Get aggregated service document");

		Get get = diversionDocument.createGet(moType, id);

		return get;
	}

	@Override
	public Delete createDelete(String moType, String id)
	{
		logger.debug("creating Delete aggregated service document");

		Delete delete = diversionDocument.createDelete(moType, id);

		return delete;
	}

	@Override
	public CreateMMTel createDefault()
	{
		CreateMMTel mmtel = diversionDocument.getFactory().createCreateMMTel();

		JAXBElement<CommunicationDiversionType> communicationDiversion = diversionDocument.createDefault();

		JAXBElement<String> publicIdentity = diversionDocument.getFactory().createCreateMMTelPublicId(
				"sip:lulseged.zerfu@ericsson.com");

		mmtel.setPublicIdentityElement(publicIdentity);

		mmtel.setCommunicationDiversion(communicationDiversion);

		return mmtel;
	}
}
