using System.Linq;

using BeWo.Data.Access;
using BeWo.Data.Entities;

using BS.Shared.DataContracts.Compact;

namespace BeWo.Service.DCEntityMapper
{
    public class CompactCustomerDC_CustomerCompact : AbstractIDCEntityMapper<Customer, CompactCustomerDC>
    {
        public override CompactCustomerDC MergeWithDC(Customer pEntity, CompactCustomerDC pDataContract)
        {
            pDataContract.CustomerOid         = pEntity.Oid.Value;
            pDataContract.CustomerVersion     = pEntity.Version.Value;
            pDataContract.FirstName           = pEntity.Person.FirstName;
            pDataContract.LastName            = pEntity.Person.LastName;
            pDataContract.DateOfBirth         = pEntity.Person.DateOfBirth;
			pDataContract.Sex                 = pEntity.Person.Sex;
            pDataContract.ActivationType      = pEntity.IsActive;
            pDataContract.AssistanceBegin     = pEntity.AssistanceBegin;
            pDataContract.TerminationDate     = pEntity.TerminationDate;
            pDataContract.EquityContribution  = pEntity.EquityContribution;
	        pDataContract.RelatedTeamOids     = pEntity.Team2CustomerList.Select(t2c => t2c.CustomerOid.Value).ToList();
            pDataContract.CustomerAlias       = pEntity.CustomerAlias;

            return pDataContract;
        }

        // Are not editable
        public override Customer MergeWithEntity(CompactCustomerDC pDataContract, Customer pEntity)
        {
            return DAOFactory.GenericDAO.LoadByID<Customer>(pDataContract.CustomerOid);
        }

        protected override bool AreDCAndEntityEqual(CompactCustomerDC pDC, Customer pEntity)
        {
            return pDC.CustomerOid == pEntity.Oid;
        }
    }
}