// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.

namespace Microsoft.Azure.Management.ApiManagement.Models
{
    using Microsoft.Azure;
    using Microsoft.Azure.Management;
    using Microsoft.Azure.Management.ApiManagement;
    using Microsoft.Rest;
    using Microsoft.Rest.Serialization;
    using Newtonsoft.Json;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;

    /// <summary>
    /// Email Template details.
    /// </summary>
    [Rest.Serialization.JsonTransformation]
    public partial class EmailTemplateContract : Resource
    {
        /// <summary>
        /// Initializes a new instance of the EmailTemplateContract class.
        /// </summary>
        public EmailTemplateContract()
        {
          CustomInit();
        }

        /// <summary>
        /// Initializes a new instance of the EmailTemplateContract class.
        /// </summary>
        /// <param name="subject">Subject of the Template.</param>
        /// <param name="body">Email Template Body. This should be a valid
        /// XDocument</param>
        /// <param name="id">Resource ID.</param>
        /// <param name="name">Resource name.</param>
        /// <param name="type">Resource type for API Management
        /// resource.</param>
        /// <param name="title">Title of the Template.</param>
        /// <param name="description">Description of the Email
        /// Template.</param>
        /// <param name="isDefault">Whether the template is the default
        /// template provided by Api Management or has been edited.</param>
        /// <param name="parameters">Email Template Parameter values.</param>
        public EmailTemplateContract(string subject, string body, string id = default(string), string name = default(string), string type = default(string), string title = default(string), string description = default(string), bool? isDefault = default(bool?), IList<EmailTemplateParametersContractProperties> parameters = default(IList<EmailTemplateParametersContractProperties>))
            : base(id, name, type)
        {
            Subject = subject;
            Body = body;
            Title = title;
            Description = description;
            IsDefault = isDefault;
            Parameters = parameters;
            CustomInit();
        }

        /// <summary>
        /// An initialization method that performs custom operations like setting defaults
        /// </summary>
        partial void CustomInit();

        /// <summary>
        /// Gets or sets subject of the Template.
        /// </summary>
        [JsonProperty(PropertyName = "properties.subject")]
        public string Subject { get; set; }

        /// <summary>
        /// Gets or sets email Template Body. This should be a valid XDocument
        /// </summary>
        [JsonProperty(PropertyName = "properties.body")]
        public string Body { get; set; }

        /// <summary>
        /// Gets or sets title of the Template.
        /// </summary>
        [JsonProperty(PropertyName = "properties.title")]
        public string Title { get; set; }

        /// <summary>
        /// Gets or sets description of the Email Template.
        /// </summary>
        [JsonProperty(PropertyName = "properties.description")]
        public string Description { get; set; }

        /// <summary>
        /// Gets whether the template is the default template provided by Api
        /// Management or has been edited.
        /// </summary>
        [JsonProperty(PropertyName = "properties.isDefault")]
        public bool? IsDefault { get; private set; }

        /// <summary>
        /// Gets or sets email Template Parameter values.
        /// </summary>
        [JsonProperty(PropertyName = "properties.parameters")]
        public IList<EmailTemplateParametersContractProperties> Parameters { get; set; }

        /// <summary>
        /// Validate the object.
        /// </summary>
        /// <exception cref="ValidationException">
        /// Thrown if validation fails
        /// </exception>
        public virtual void Validate()
        {
            if (Subject == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "Subject");
            }
            if (Body == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "Body");
            }
            if (Subject != null)
            {
                if (Subject.Length > 1000)
                {
                    throw new ValidationException(ValidationRules.MaxLength, "Subject", 1000);
                }
                if (Subject.Length < 1)
                {
                    throw new ValidationException(ValidationRules.MinLength, "Subject", 1);
                }
            }
            if (Body != null)
            {
                if (Body.Length < 1)
                {
                    throw new ValidationException(ValidationRules.MinLength, "Body", 1);
                }
            }
            if (Parameters != null)
            {
                foreach (var element in Parameters)
                {
                    if (element != null)
                    {
                        element.Validate();
                    }
                }
            }
        }
    }
}
