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

namespace TelerikMVC3Test.Models
{
    public enum PasswordStrengthTypes
    {
        OnlyMinimumMaximumLength = 1,
        LowerCaseUpperCase,
        LowerCaseUpperCaseNumber,
        LowerCaseUpperCaseNumberSpecialCharacter
    }

    public class SettingsViewModel : IValidatableObject
    {
        public SettingsViewModel()
        {
            this.PasswordNeverExpires = true;
            this.PasswordExpirationValue = null;
            this.PasswordExpirationUnit = 0;

            PasswordStrengths = new Dictionary<int, string>
            {
                { 0, "---Select---" },
                { 1, PasswordStrengthTypes.OnlyMinimumMaximumLength.ToString() },
                { 2, PasswordStrengthTypes.LowerCaseUpperCase.ToString() },
                { 3, PasswordStrengthTypes.LowerCaseUpperCaseNumber.ToString() },
                { 4, PasswordStrengthTypes.LowerCaseUpperCaseNumberSpecialCharacter.ToString() }
            };
        }

        public IDictionary<int, string> PasswordStrengths { get; set; }

        [Display( Name = "Password" )]
        public bool PasswordNeverExpires { get; set; }

        [Display( Name = "Password" )]
        [DataType( "Integer" )]
        public int? PasswordExpirationValue { get; set; }

        [UIHint( "TimeUnit" )]
        public int PasswordExpirationUnit { get; set; }

        [Range( 1, 4, ErrorMessage = "Error -> PasswordStrength" )]
        public PasswordStrengthTypes PasswordStrength { get; set; }

        public IEnumerable<ValidationResult> Validate( ValidationContext validationContext )
        {
            if( !this.PasswordNeverExpires && ( this.PasswordExpirationValue == null || this.PasswordExpirationUnit == 0 ) )
            {
                yield return new ValidationResult( "Error...", new string[] { "PasswordExpirationUnit" } );
            }
        }
    }
}