using System.ComponentModel;

using BS.Shared;

using BeWo.ViewModel;
using BS.Shared.DataContracts.ClientPartials;

namespace BeWo.Core
{
    public class SupportConceptGoalTreeItem : SupportConceptGoalDC
    {
        private ValueListEntryVM _GoalEntryVM;

        private BindingList<SupportConceptGoalTreeItem> _Children;

        public ValueListEntryVM GoalEntryVM
        {
            get
            {
                return _GoalEntryVM;
            }

            set
            {
                _GoalEntryVM = value;
            }
        }

        public string ItemName
        {
            get
            {
                if (_GoalEntryVM != null)
                {
                    return _GoalEntryVM.Description;
                }

                return GoalEntryDC != null ? GoalEntryDC.TypeDescription : null;
            }
            set
            {
                if (_GoalEntryVM != null)
                {
                    _GoalEntryVM.Description = value;
                }
                if (GoalEntryDC != null)
                {
                    GoalEntryDC.TypeDescription = value;
                }
            }
        }

	    public bool IsGoal
	    {
            get 
            { 
                return GoalEntryVM != null ? 
                    GoalEntryVM.Type.Equals(ValueListEntryType.SupportConceptGoalType) || GoalEntryVM.Type.Equals(ValueListEntryType.SupportConceptIndividualGoalType) : 
                    GoalEntryDC.Type.Equals(ValueListEntryType.SupportConceptGoalType) || GoalEntryDC.Type.Equals(ValueListEntryType.SupportConceptIndividualGoalType); 
            }
	    }

	    public BindingList<SupportConceptGoalTreeItem> Items
        {
            get
            {
                return _Children ?? (_Children = new BindingList<SupportConceptGoalTreeItem>());
            }

            set
            {
                _Children = value;
            }
        }

        public ValueListEntryType GoalType
        {
            get { return GoalEntryDC == null ? GoalEntryVM.Type : GoalEntryDC.Type; }
        }
    }
}