// <auto-generated>
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>

namespace k8s.Models
{
    using Microsoft.Rest;
    using Newtonsoft.Json;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;

    /// <summary>
    /// CustomResourceConversion describes how to convert different versions of
    /// a CR.
    /// </summary>
    public partial class V1beta1CustomResourceConversion
    {
        /// <summary>
        /// Initializes a new instance of the V1beta1CustomResourceConversion
        /// class.
        /// </summary>
        public V1beta1CustomResourceConversion()
        {
            CustomInit();
        }

        /// <summary>
        /// Initializes a new instance of the V1beta1CustomResourceConversion
        /// class.
        /// </summary>
        /// <param name="strategy">strategy specifies how custom resources are
        /// converted between versions. Allowed values are: - `None`: The
        /// converter only change the apiVersion and would not touch any other
        /// field in the custom resource. - `Webhook`: API Server will call to
        /// an external webhook to do the conversion. Additional information
        /// is needed for this option. This requires spec.preserveUnknownFields
        /// to be false, and spec.conversion.webhookClientConfig to be
        /// set.</param>
        /// <param name="conversionReviewVersions">conversionReviewVersions is
        /// an ordered list of preferred `ConversionReview` versions the
        /// Webhook expects. The API server will use the first version in the
        /// list which it supports. If none of the versions specified in this
        /// list are supported by API server, conversion will fail for the
        /// custom resource. If a persisted Webhook configuration specifies
        /// allowed versions and does not include any versions known to the API
        /// Server, calls to the webhook will fail. Defaults to
        /// `["v1beta1"]`.</param>
        /// <param name="webhookClientConfig">webhookClientConfig is the
        /// instructions for how to call the webhook if strategy is `Webhook`.
        /// Required when `strategy` is set to `Webhook`.</param>
        public V1beta1CustomResourceConversion(string strategy, IList<string> conversionReviewVersions = default(IList<string>), Apiextensionsv1beta1WebhookClientConfig webhookClientConfig = default(Apiextensionsv1beta1WebhookClientConfig))
        {
            ConversionReviewVersions = conversionReviewVersions;
            Strategy = strategy;
            WebhookClientConfig = webhookClientConfig;
            CustomInit();
        }

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

        /// <summary>
        /// Gets or sets conversionReviewVersions is an ordered list of
        /// preferred `ConversionReview` versions the Webhook expects. The API
        /// server will use the first version in the list which it supports. If
        /// none of the versions specified in this list are supported by API
        /// server, conversion will fail for the custom resource. If a
        /// persisted Webhook configuration specifies allowed versions and does
        /// not include any versions known to the API Server, calls to the
        /// webhook will fail. Defaults to `["v1beta1"]`.
        /// </summary>
        [JsonProperty(PropertyName = "conversionReviewVersions")]
        public IList<string> ConversionReviewVersions { get; set; }

        /// <summary>
        /// Gets or sets strategy specifies how custom resources are converted
        /// between versions. Allowed values are: - `None`: The converter only
        /// change the apiVersion and would not touch any other field in the
        /// custom resource. - `Webhook`: API Server will call to an external
        /// webhook to do the conversion. Additional information
        /// is needed for this option. This requires spec.preserveUnknownFields
        /// to be false, and spec.conversion.webhookClientConfig to be set.
        /// </summary>
        [JsonProperty(PropertyName = "strategy")]
        public string Strategy { get; set; }

        /// <summary>
        /// Gets or sets webhookClientConfig is the instructions for how to
        /// call the webhook if strategy is `Webhook`. Required when `strategy`
        /// is set to `Webhook`.
        /// </summary>
        [JsonProperty(PropertyName = "webhookClientConfig")]
        public Apiextensionsv1beta1WebhookClientConfig WebhookClientConfig { get; set; }

        /// <summary>
        /// Validate the object.
        /// </summary>
        /// <exception cref="ValidationException">
        /// Thrown if validation fails
        /// </exception>
        public virtual void Validate()
        {
            if (Strategy == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "Strategy");
            }
            if (WebhookClientConfig != null)
            {
                WebhookClientConfig.Validate();
            }
        }
    }
}
