using System.Collections.Generic;
using System.Drawing;
using BS.Shared;
using BS.Shared.DataContracts;

namespace BeWo.ViewModel
{
    public class VarFieldVM : AbstractDCMapperVM<VarFieldDC>
    {
        public static string PropertyName_VarFieldValue = "VarFieldValue";

        private object _VarFieldValue;

        public VarFieldVM(VarFieldDC pDataContract) : base(pDataContract, false)
        {
        }

        public int ColumnSpan { get; private set; }

        public ControlType ControlType { get; private set; }

        public int DecimalPlaces { get; private set; }

        public string Group { get; private set; }

        public int? Height { get; private set; }

        public string Label { get; private set; }

        public List<string> PossibleItems { get; private set; }

        public int RowSpan { get; private set; }

        public object VarFieldValue
        {
            get { return this._VarFieldValue; }

            set
            {
                if (this.AreDifferent(this._VarFieldValue, value))
                {
                    this._VarFieldValue = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.VarFieldValue, value), PropertyName_VarFieldValue);
                    this.FirePropertyChanged(PropertyName_VarFieldValue);
                }
            }
        }

        public bool VarFieldValueBoolean
        {
            get
            {
                if (this._VarFieldValue == null)
                    return false;
                return bool.Parse(this._VarFieldValue.ToString());
            }

            set
            {
                VarFieldValue = value;
            }
        }

        public int? Width { get; private set; }

        public int XCoordinate { get; private set; }

        public int YCoordinate { get; private set; }

        protected override void InitByDataContract(VarFieldDC pDataContract)
        {
            this.Group = pDataContract.Group;
            this.XCoordinate = pDataContract.XCoordinate;
            this.YCoordinate = pDataContract.YCoordinate;
            this.Label = pDataContract.Label;
            this.ControlType = pDataContract.ControlType;
            this.PossibleItems = pDataContract.PossibleItems;
            this.DecimalPlaces = pDataContract.DecimalPlaces;
            this._VarFieldValue = pDataContract.VarFieldValue;
            this.Width = pDataContract.Width;
            this.ColumnSpan = pDataContract.ColumnSpan ?? 1;
            this.RowSpan = pDataContract.RowSpan ?? 1;
            this.Height = pDataContract.Height;
        }

        protected override VarFieldDC MapToDataContract(VarFieldDC pDataContract, bool doCommit)
        {
            pDataContract.VarFieldValue = this._VarFieldValue;
            return pDataContract;
        }
    }
}