using System.Windows.Media;

using BeWo.Validation;

using BS.Shared.DataContracts;
using BS.Shared.Extensions;

namespace BeWo.ViewModel
{
    public class AssessmentSheetValueVM : AbstractDCMapperVM<AssessmentSheetValueDC>
    {
        public static string PropertyName_Brush = "Brush";

        public static string PropertyName_Description = "Description";

        public static string PropertyName_Position = "Position";

        public static string PropertyName_ShortcutKey = "ShortcutKey";

        public static string PropertyName_Sign = "Sign";

        private SolidColorBrush _Brush;

        private string _BrushString;

        private string _Description;

        private int _Position;

        private string _ShortcutKey;

        private string _Sign;

        public AssessmentSheetValueVM(AssessmentSheetValueDC pDC) : base(pDC, pDC.AssessmentSheetValueOid == null)
        {
        }

        [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public SolidColorBrush Brush
        {
            get { return this._Brush; }

            set
            {
                if (this.AreDifferent(this._Brush, value))
                {
                    this._Brush = value;
                    this._BrushString = value.ToStringNullCheck();
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.Color, value.ToString()), PropertyName_Brush);
                    this.FirePropertyChanged(PropertyName_Brush);
                }
            }
        }

        public string Description
        {
            get { return this._Description; }

            set
            {
                if (this.AreDifferent(this._Description, value))
                {
                    this._Description = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.Description, value), PropertyName_Description);
                    this.FirePropertyChanged(PropertyName_Description);
                }
            }
        }

        public int Position
        {
            get { return this._Position; }

            set
            {
                if (this.AreDifferent(this._Position, value))
                {
                    this._Position = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.Position, value), PropertyName_Position);
                    this.FirePropertyChanged(PropertyName_Position);
                }
            }
        }

        public string ShortcutKey
        {
            get { return this._ShortcutKey; }

            set
            {
                if (this.AreDifferent(this._ShortcutKey, value))
                {
                    this._ShortcutKey = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.ShortcutKey, value), PropertyName_ShortcutKey);
                    this.FirePropertyChanged(PropertyName_ShortcutKey);
                }
            }
        }

        public string Sign
        {
            get { return this._Sign; }

            set
            {
                if (this.AreDifferent(this._Sign, value))
                {
                    this._Sign = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.Sign, value), PropertyName_Sign);
                    this.FirePropertyChanged(PropertyName_Sign);
                }
            }
        }

        public static int Compare(AssessmentSheetValueVM x, AssessmentSheetValueVM y)
        {
            if (x.Position.Equals(y.Position) && x.Description != null)
			{
                return x.Description.CompareTo(y.Description);
            }

            return x.Position.CompareTo(y.Position);
        }

        protected override void InitByDataContract(AssessmentSheetValueDC pDataContract)
        {
            this._Description = pDataContract.Description;
            if (!string.IsNullOrEmpty(pDataContract.Color))
            {
                this.Brush = (SolidColorBrush)new BrushConverter().ConvertFrom(pDataContract.Color);
            }

            this._ShortcutKey = pDataContract.ShortcutKey;
            this._Sign = pDataContract.Sign;
            this._Position = pDataContract.Position;
        }

        protected override AssessmentSheetValueDC MapToDataContract(AssessmentSheetValueDC pDataContract, bool doCommit)
        {
            pDataContract.Description = this._Description;
            pDataContract.Color = this._BrushString;
            pDataContract.ShortcutKey = this._ShortcutKey;
            pDataContract.Sign = this._Sign;
            pDataContract.Position = this._Position;
            return pDataContract;
        }
    }
}