/*
 * SMAC API
 *
 * SMAC ASP.NET Core Web API
 *
 * The version of the OpenAPI document: v1
 * Generated by: https://github.com/openapitools/openapi-generator.git
 */


using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.IO;
using System.Runtime.Serialization;
using System.Text;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using JsonSubTypes;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;

namespace Org.OpenAPITools.Model
{
    /// <summary>
    /// An email rule
    /// </summary>
    [DataContract(Name = "EmailRule")]
    [JsonConverter(typeof(JsonSubtypes), "Type")]
    [JsonSubtypes.KnownSubType(typeof(DateTimeRule), "DateTimeRule")]
    [JsonSubtypes.KnownSubType(typeof(EmailRule), "EmailRule")]
    [JsonSubtypes.KnownSubType(typeof(LocationRule), "LocationRule")]
    [JsonSubtypes.KnownSubType(typeof(ScanOptionRule), "ScanOptionRule")]
    [JsonSubtypes.KnownSubType(typeof(UserRoleRule), "UserRoleRule")]
    public partial class EmailRule : BaseRule, IEquatable<EmailRule>, IValidatableObject
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="EmailRule" /> class.
        /// </summary>
        [JsonConstructorAttribute]
        protected EmailRule() { }
        /// <summary>
        /// Initializes a new instance of the <see cref="EmailRule" /> class.
        /// </summary>
        /// <param name="allowedEmails">A comma or semicolon separated string defining the allowed emails (The allowed email take precedents if its domain is black-listed.).</param>
        /// <param name="blockedEmails">A comma or semicolon separated string defining the blocked emails (The blocked email take precedents if its domain is white-listed.).</param>
        /// <param name="domainWhiteList">A comma or semicolon separated string defining the white-listed domains (The blocked email take precedents if its domain is white-listed.).</param>
        /// <param name="domainBlackList">A comma or semicolon separated string defining the black-listed domains (The allowed email take precedents if its domain is black-listed.).</param>
        /// <param name="type">Defines the type of the rule (required) (default to &quot;EmailRule&quot;).</param>
        public EmailRule(string allowedEmails = default(string), string blockedEmails = default(string), string domainWhiteList = default(string), string domainBlackList = default(string), string type = "EmailRule") : base()
        {
            // to ensure "type" is required (not null)
            if (type == null)
            {
                throw new ArgumentNullException("type is a required property for EmailRule and cannot be null");
            }
            this.Type = type;
            this.AllowedEmails = allowedEmails;
            this.BlockedEmails = blockedEmails;
            this.DomainWhiteList = domainWhiteList;
            this.DomainBlackList = domainBlackList;
        }

        /// <summary>
        /// A comma or semicolon separated string defining the allowed emails (The allowed email take precedents if its domain is black-listed.)
        /// </summary>
        /// <value>A comma or semicolon separated string defining the allowed emails (The allowed email take precedents if its domain is black-listed.)</value>
        [DataMember(Name = "allowedEmails", EmitDefaultValue = true)]
        public string AllowedEmails { get; set; }

        /// <summary>
        /// A comma or semicolon separated string defining the blocked emails (The blocked email take precedents if its domain is white-listed.)
        /// </summary>
        /// <value>A comma or semicolon separated string defining the blocked emails (The blocked email take precedents if its domain is white-listed.)</value>
        [DataMember(Name = "blockedEmails", EmitDefaultValue = true)]
        public string BlockedEmails { get; set; }

        /// <summary>
        /// A comma or semicolon separated string defining the white-listed domains (The blocked email take precedents if its domain is white-listed.)
        /// </summary>
        /// <value>A comma or semicolon separated string defining the white-listed domains (The blocked email take precedents if its domain is white-listed.)</value>
        [DataMember(Name = "domainWhiteList", EmitDefaultValue = true)]
        public string DomainWhiteList { get; set; }

        /// <summary>
        /// A comma or semicolon separated string defining the black-listed domains (The allowed email take precedents if its domain is black-listed.)
        /// </summary>
        /// <value>A comma or semicolon separated string defining the black-listed domains (The allowed email take precedents if its domain is black-listed.)</value>
        [DataMember(Name = "domainBlackList", EmitDefaultValue = true)]
        public string DomainBlackList { get; set; }

        /// <summary>
        /// Defines the type of the rule
        /// </summary>
        /// <value>Defines the type of the rule</value>
        [DataMember(Name = "type", IsRequired = true, EmitDefaultValue = true)]
        public string Type { get; set; }

        /// <summary>
        /// Returns the string presentation of the object
        /// </summary>
        /// <returns>String presentation of the object</returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("class EmailRule {\n");
            sb.Append("  ").Append(base.ToString().Replace("\n", "\n  ")).Append("\n");
            sb.Append("  AllowedEmails: ").Append(AllowedEmails).Append("\n");
            sb.Append("  BlockedEmails: ").Append(BlockedEmails).Append("\n");
            sb.Append("  DomainWhiteList: ").Append(DomainWhiteList).Append("\n");
            sb.Append("  DomainBlackList: ").Append(DomainBlackList).Append("\n");
            sb.Append("  Type: ").Append(Type).Append("\n");
            sb.Append("}\n");
            return sb.ToString();
        }

        /// <summary>
        /// Returns the JSON string presentation of the object
        /// </summary>
        /// <returns>JSON string presentation of the object</returns>
        public override string ToJson()
        {
            return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
        }

        /// <summary>
        /// Returns true if objects are equal
        /// </summary>
        /// <param name="input">Object to be compared</param>
        /// <returns>Boolean</returns>
        public override bool Equals(object input)
        {
            return this.Equals(input as EmailRule);
        }

        /// <summary>
        /// Returns true if EmailRule instances are equal
        /// </summary>
        /// <param name="input">Instance of EmailRule to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(EmailRule input)
        {
            if (input == null)
            {
                return false;
            }
            return base.Equals(input) && 
                (
                    this.AllowedEmails == input.AllowedEmails ||
                    (this.AllowedEmails != null &&
                    this.AllowedEmails.Equals(input.AllowedEmails))
                ) && base.Equals(input) && 
                (
                    this.BlockedEmails == input.BlockedEmails ||
                    (this.BlockedEmails != null &&
                    this.BlockedEmails.Equals(input.BlockedEmails))
                ) && base.Equals(input) && 
                (
                    this.DomainWhiteList == input.DomainWhiteList ||
                    (this.DomainWhiteList != null &&
                    this.DomainWhiteList.Equals(input.DomainWhiteList))
                ) && base.Equals(input) && 
                (
                    this.DomainBlackList == input.DomainBlackList ||
                    (this.DomainBlackList != null &&
                    this.DomainBlackList.Equals(input.DomainBlackList))
                ) && base.Equals(input) && 
                (
                    this.Type == input.Type ||
                    (this.Type != null &&
                    this.Type.Equals(input.Type))
                );
        }

        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                int hashCode = base.GetHashCode();
                if (this.AllowedEmails != null)
                {
                    hashCode = (hashCode * 59) + this.AllowedEmails.GetHashCode();
                }
                if (this.BlockedEmails != null)
                {
                    hashCode = (hashCode * 59) + this.BlockedEmails.GetHashCode();
                }
                if (this.DomainWhiteList != null)
                {
                    hashCode = (hashCode * 59) + this.DomainWhiteList.GetHashCode();
                }
                if (this.DomainBlackList != null)
                {
                    hashCode = (hashCode * 59) + this.DomainBlackList.GetHashCode();
                }
                if (this.Type != null)
                {
                    hashCode = (hashCode * 59) + this.Type.GetHashCode();
                }
                return hashCode;
            }
        }

        /// <summary>
        /// To validate all properties of the instance
        /// </summary>
        /// <param name="validationContext">Validation context</param>
        /// <returns>Validation Result</returns>
        public IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> Validate(ValidationContext validationContext)
        {
            return this.BaseValidate(validationContext);
        }

        /// <summary>
        /// To validate all properties of the instance
        /// </summary>
        /// <param name="validationContext">Validation context</param>
        /// <returns>Validation Result</returns>
        protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
        {
            foreach (var x in base.BaseValidate(validationContext))
            {
                yield return x;
            }
            // AllowedEmails (string) pattern
            Regex regexAllowedEmails = new Regex(@"^(([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)(\\s*(;|,)\\s*|\\s*$))*$", RegexOptions.CultureInvariant);
            if (false == regexAllowedEmails.Match(this.AllowedEmails).Success)
            {
                yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for AllowedEmails, must match a pattern of " + regexAllowedEmails, new [] { "AllowedEmails" });
            }

            // BlockedEmails (string) pattern
            Regex regexBlockedEmails = new Regex(@"^(([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)(\\s*(;|,)\\s*|\\s*$))*$", RegexOptions.CultureInvariant);
            if (false == regexBlockedEmails.Match(this.BlockedEmails).Success)
            {
                yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for BlockedEmails, must match a pattern of " + regexBlockedEmails, new [] { "BlockedEmails" });
            }

            // Type (string) minLength
            if (this.Type != null && this.Type.Length < 1)
            {
                yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Type, length must be greater than 1.", new [] { "Type" });
            }

            yield break;
        }
    }

}
