using System;
using System.Collections.Generic;
using System.Text;

namespace EnterpriseDesktop.Common.Validation
{
    /// <summary>
    /// Base business entity class that provides validation.
    /// </summary>
    public class BusinessEntity : IValidate
    {
        public BusinessEntity()
        {
            _validateRules = new List<Rule>();
            _brokenRules = new BrokenRulesList();
        }

        private List<Rule> _validateRules;
        /// <summary>
        /// List of Rule objects that need to be valid for this business entity
        /// to pass inspection.
        /// </summary>
        public List<Rule> ValidateRules
        {
            get { return _validateRules; }
            set { _validateRules = value; }
        }

        private BrokenRulesList _brokenRules;
        /// <summary>
        /// Collection of broken rules.
        /// </summary>
        public BrokenRulesList BrokenRules
        {
            get { return _brokenRules; }
            set { _brokenRules = value; }
        }

        /// <summary>
        /// Validate the business entity.
        /// </summary>
        public void Validate()
        {
            foreach (Rule rule in _validateRules)
            {
                if (!rule.Invoke(this))
                {
                    _brokenRules.Add(rule);
                }
            }
        }
    }
}
