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

namespace EnterpriseDesktop.Common.Validation
{
    /// <summary>
    /// Business rule that is to be validated against a business entity.
    /// </summary>
    public class Rule
    {
        public Rule()
        {

        }

        private string _propertyName;

        /// <summary>
        /// Property that is being evaluated.
        /// </summary>
        [System.Xml.Serialization.XmlAttribute("property")]
        public string PropertyName
        {
            get { return _propertyName; }
            set { _propertyName = value; }
        }

        private string _errorMsg;

        [System.Xml.Serialization.XmlAttribute("error")]
        public string ErrorMsg
        {
            get { return _errorMsg; }
            set { _errorMsg = value; }
        }
	

        public Rule(string property, string errorMessage, ValidationDelegate method)
        {
            _propertyName = property;
            _errorMsg = errorMessage;
            _method = method;
        }

        private ValidationDelegate  _method;

        [System.Xml.Serialization.XmlIgnore()]
        public ValidationDelegate  Method
        {
            get { return _method; }
            set { _method = value; }
        }
	
        public void RuleHandler(ValidationDelegate methodName)
        {
            _method = methodName;
        }

        public bool Invoke(object entity)
        {
            return _method.Invoke(entity, _propertyName);
        }
	
    }
}
