using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace WebApplication1.Models {

  public enum Niveau {
    Secret,
    [Display(Name = "Très secret")]
    TresSecret,
    [Display(Name = "Très très secret")]
    TresTresSecret
  }

  public class AgentSecret {
    [Required( ErrorMessage = "T'es timide ? Donne ton nom !" )]
    [StringLength( 50, MinimumLength = 5, ErrorMessage = "Entre 5 et 10 caractères" )]
    public string Nom { get; set; }
    [Remote( "ValiderCodeSecret", "ExempleValidationAvecRemote", AdditionalFields = "Nom", ErrorMessage = "Code erroné" )]
    [Display( Name = "Code secret" )]
    [DataType( DataType.Password )]
    public string CodeSecret { get; set; }
    // [ . . . ]
    [CustomValidation( typeof( MissionValidator ), "ValiderMission", ErrorMessage = "Mission non approuvée" )]
    public string Mission { get; set; }
    public Niveau Niveau { get; set; }
  }

  public static class MissionValidator {
    public static ValidationResult ValiderMission( string mission ) {
      if( !string.IsNullOrWhiteSpace(mission) && mission.ToUpper() == mission )
        return ValidationResult.Success;
      else
        return new ValidationResult( null ); // Pour utiliser le msg d'erreur par défaut
    }
  }
}
