using BeWo.Validation;
using BS.Shared.Extensions;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;

namespace BeWo.ViewModel
{
    public class CustomerTeamRelationVM : AbstractDCMapperVM<CustomerTeamRelationDC>
    {
        public static string PropertyName_Team = "Team";
        public static string PropertyName_TeamString = "TeamString";
        public static string PropertyName_Customer = "Customer";
        public static string PropertyName_CustomerString = "CustomerString";
        public static string PropertyName_Role = "Role";
        public static string PropertyName_Notice = "Notice";

        private CompactTeamDC _Team;
        private CompactCustomerDC _Customer;
        private ValueListEntryDC _Role;
        private string _Notice;

        public string Notice
        {
            get { return _Notice; }
            set
            {
                if (base.AreDifferent(_Notice, value))
                {
                    _Notice = value;
                    StoreDirtyInformation(AreDifferent(DataContract.Notice, value), PropertyName_Notice);
                    FirePropertyChanged(PropertyName_Notice);
                }
            }
        }

        [ValidationAttribute(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public ValueListEntryDC Role
        {
            get { return _Role; }
            set
            {
                if (base.AreDifferent(_Role, value))
                {
                    _Role = value;
                    StoreDirtyInformation(AreDifferent(DataContract.RelationRole, value), PropertyName_Role);
                    FirePropertyChanged(PropertyName_Role);
                }
            }
        }

        [ValidationAttribute(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public string TeamString
        {
            get { return _Team.ToStringNullCheck(); }
            //Validation Workaround
            set { }
        }

        [ValidationAttribute(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public CompactTeamDC Team
        {
            get { return _Team; }
            set
            {
                if (base.AreDifferent(_Team, value))
                {
                    _Team = value;
                    StoreDirtyInformation(AreDifferent(DataContract.Team, value), PropertyName_Team);
                    FirePropertyChanged(PropertyName_Team);
                    FirePropertyChanged(PropertyName_TeamString);
                }
            }
        }

        [ValidationAttribute(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public string CustomerString
        {
            get { return _Customer.ToStringNullCheck(); }
            //Validation Workaround
            set { }
        }

        [ValidationAttribute(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public CompactCustomerDC Customer
        {
            get { return _Customer; }
            set
            {
                if (base.AreDifferent(_Customer, value))
                {
                    _Customer = value;
                    StoreDirtyInformation(AreDifferent(DataContract.Customer, value), PropertyName_Customer);
                    FirePropertyChanged(PropertyName_Customer);
                    FirePropertyChanged(PropertyName_CustomerString);
                }
            }
        }

        public CustomerTeamRelationVM(CustomerTeamRelationDC pDC) : base(pDC, pDC.Team2CustomerOid == null) { }

        protected override void InitByDataContract(CustomerTeamRelationDC pDataContract)
        {
            if (!IsNew)
            {
                _Team = pDataContract.Team;
                _Customer = pDataContract.Customer;
                _Role = pDataContract.RelationRole;
                _Notice = pDataContract.Notice;
            }
        }

        protected override CustomerTeamRelationDC MapToDataContract(CustomerTeamRelationDC pDataContract, bool doCommit)
        {
            pDataContract.Team = _Team;
            pDataContract.Customer = _Customer;
            pDataContract.RelationRole = _Role;
            pDataContract.Notice = _Notice;

            return DataContract;
        }
    }
}
