using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

using VRH.Log4Pro.MultiLanguageManager;

namespace Vrh.Web.iScheduler
{
    /// <summary>
    /// 
    /// </summary>
    public class LocaleRequiredAttribute : RequiredAttribute, IClientValidatable
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public override string FormatErrorMessage(string name)
        {
            //System.Diagnostics.Debug.WriteLine("RequiredLocaleAttribute name = {0}", name, null);
            ErrorMessage = MultiLanguageManager.GetTranslation(typeof(GeneralWordCodes.MLM.General.Messages.RequiredWithName));
            return base.FormatErrorMessage(name);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="metadata"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            yield return new ModelClientValidationRule
            {
                // format the error message to include the property's display name.
                ErrorMessage = FormatErrorMessage(metadata.DisplayName),

                // uses the required validation type.
                ValidationType = "required"
            };
        }

    }
}
