// <auto-generated>
/*
 * OpenAPI Petstore
 *
 * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
 *
 * The version of the OpenAPI document: 1.0.0
 * 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.Text;
using System.Text.RegularExpressions;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.ComponentModel.DataAnnotations;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using Org.OpenAPITools.Client;

namespace Org.OpenAPITools.Model
{
    /// <summary>
    /// EnumTest
    /// </summary>
    public partial class EnumTest : IValidatableObject
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="EnumTest" /> class.
        /// </summary>
        /// <param name="enumStringRequired">enumStringRequired</param>
        /// <param name="enumInteger">enumInteger</param>
        /// <param name="enumIntegerOnly">enumIntegerOnly</param>
        /// <param name="enumNumber">enumNumber</param>
        /// <param name="enumString">enumString</param>
        /// <param name="outerEnum">outerEnum</param>
        /// <param name="outerEnumDefaultValue">outerEnumDefaultValue</param>
        /// <param name="outerEnumInteger">outerEnumInteger</param>
        /// <param name="outerEnumIntegerDefaultValue">outerEnumIntegerDefaultValue</param>
        [JsonConstructor]
        public EnumTest(EnumTestEnumString enumStringRequired, Option<EnumTestEnumInteger?> enumInteger = default, Option<EnumTestEnumIntegerOnly?> enumIntegerOnly = default, Option<TestEnumParametersEnumQueryDoubleParameter?> enumNumber = default, Option<EnumTestEnumString?> enumString = default, Option<OuterEnum?> outerEnum = default, Option<OuterEnumDefaultValue?> outerEnumDefaultValue = default, Option<OuterEnumInteger?> outerEnumInteger = default, Option<OuterEnumIntegerDefaultValue?> outerEnumIntegerDefaultValue = default)
        {
            EnumStringRequired = enumStringRequired;
            EnumIntegerOption = enumInteger;
            EnumIntegerOnlyOption = enumIntegerOnly;
            EnumNumberOption = enumNumber;
            EnumStringOption = enumString;
            OuterEnumOption = outerEnum;
            OuterEnumDefaultValueOption = outerEnumDefaultValue;
            OuterEnumIntegerOption = outerEnumInteger;
            OuterEnumIntegerDefaultValueOption = outerEnumIntegerDefaultValue;
            OnCreated();
        }

        partial void OnCreated();

        /// <summary>
        /// Gets or Sets EnumStringRequired
        /// </summary>
        [JsonPropertyName("enum_string_required")]
        public EnumTestEnumString EnumStringRequired { get; set; }

        /// <summary>
        /// Used to track the state of EnumInteger
        /// </summary>
        [JsonIgnore]
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
        public Option<EnumTestEnumInteger?> EnumIntegerOption { get; private set; }

        /// <summary>
        /// Gets or Sets EnumInteger
        /// </summary>
        [JsonPropertyName("enum_integer")]
        public EnumTestEnumInteger? EnumInteger { get { return this.EnumIntegerOption; } set { this.EnumIntegerOption = new(value); } }

        /// <summary>
        /// Used to track the state of EnumIntegerOnly
        /// </summary>
        [JsonIgnore]
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
        public Option<EnumTestEnumIntegerOnly?> EnumIntegerOnlyOption { get; private set; }

        /// <summary>
        /// Gets or Sets EnumIntegerOnly
        /// </summary>
        [JsonPropertyName("enum_integer_only")]
        public EnumTestEnumIntegerOnly? EnumIntegerOnly { get { return this.EnumIntegerOnlyOption; } set { this.EnumIntegerOnlyOption = new(value); } }

        /// <summary>
        /// Used to track the state of EnumNumber
        /// </summary>
        [JsonIgnore]
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
        public Option<TestEnumParametersEnumQueryDoubleParameter?> EnumNumberOption { get; private set; }

        /// <summary>
        /// Gets or Sets EnumNumber
        /// </summary>
        [JsonPropertyName("enum_number")]
        public TestEnumParametersEnumQueryDoubleParameter? EnumNumber { get { return this.EnumNumberOption; } set { this.EnumNumberOption = new(value); } }

        /// <summary>
        /// Used to track the state of EnumString
        /// </summary>
        [JsonIgnore]
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
        public Option<EnumTestEnumString?> EnumStringOption { get; private set; }

        /// <summary>
        /// Gets or Sets EnumString
        /// </summary>
        [JsonPropertyName("enum_string")]
        public EnumTestEnumString? EnumString { get { return this.EnumStringOption; } set { this.EnumStringOption = new(value); } }

        /// <summary>
        /// Used to track the state of OuterEnum
        /// </summary>
        [JsonIgnore]
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
        public Option<OuterEnum?> OuterEnumOption { get; private set; }

        /// <summary>
        /// Gets or Sets OuterEnum
        /// </summary>
        [JsonPropertyName("outerEnum")]
        public OuterEnum? OuterEnum { get { return this.OuterEnumOption; } set { this.OuterEnumOption = new(value); } }

        /// <summary>
        /// Used to track the state of OuterEnumDefaultValue
        /// </summary>
        [JsonIgnore]
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
        public Option<OuterEnumDefaultValue?> OuterEnumDefaultValueOption { get; private set; }

        /// <summary>
        /// Gets or Sets OuterEnumDefaultValue
        /// </summary>
        [JsonPropertyName("outerEnumDefaultValue")]
        public OuterEnumDefaultValue? OuterEnumDefaultValue { get { return this.OuterEnumDefaultValueOption; } set { this.OuterEnumDefaultValueOption = new(value); } }

        /// <summary>
        /// Used to track the state of OuterEnumInteger
        /// </summary>
        [JsonIgnore]
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
        public Option<OuterEnumInteger?> OuterEnumIntegerOption { get; private set; }

        /// <summary>
        /// Gets or Sets OuterEnumInteger
        /// </summary>
        [JsonPropertyName("outerEnumInteger")]
        public OuterEnumInteger? OuterEnumInteger { get { return this.OuterEnumIntegerOption; } set { this.OuterEnumIntegerOption = new(value); } }

        /// <summary>
        /// Used to track the state of OuterEnumIntegerDefaultValue
        /// </summary>
        [JsonIgnore]
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
        public Option<OuterEnumIntegerDefaultValue?> OuterEnumIntegerDefaultValueOption { get; private set; }

        /// <summary>
        /// Gets or Sets OuterEnumIntegerDefaultValue
        /// </summary>
        [JsonPropertyName("outerEnumIntegerDefaultValue")]
        public OuterEnumIntegerDefaultValue? OuterEnumIntegerDefaultValue { get { return this.OuterEnumIntegerDefaultValueOption; } set { this.OuterEnumIntegerDefaultValueOption = new(value); } }

        /// <summary>
        /// Gets or Sets additional properties
        /// </summary>
        [JsonExtensionData]
        public Dictionary<string, JsonElement> AdditionalProperties { get; } = new Dictionary<string, JsonElement>();

        /// <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 EnumTest {\n");
            sb.Append("  EnumStringRequired: ").Append(EnumStringRequired).Append("\n");
            sb.Append("  EnumInteger: ").Append(EnumInteger).Append("\n");
            sb.Append("  EnumIntegerOnly: ").Append(EnumIntegerOnly).Append("\n");
            sb.Append("  EnumNumber: ").Append(EnumNumber).Append("\n");
            sb.Append("  EnumString: ").Append(EnumString).Append("\n");
            sb.Append("  OuterEnum: ").Append(OuterEnum).Append("\n");
            sb.Append("  OuterEnumDefaultValue: ").Append(OuterEnumDefaultValue).Append("\n");
            sb.Append("  OuterEnumInteger: ").Append(OuterEnumInteger).Append("\n");
            sb.Append("  OuterEnumIntegerDefaultValue: ").Append(OuterEnumIntegerDefaultValue).Append("\n");
            sb.Append("  AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
            sb.Append("}\n");
            return sb.ToString();
        }

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

    /// <summary>
    /// A Json converter for type <see cref="EnumTest" />
    /// </summary>
    public class EnumTestJsonConverter : JsonConverter<EnumTest>
    {
        /// <summary>
        /// Deserializes json to <see cref="EnumTest" />
        /// </summary>
        /// <param name="utf8JsonReader"></param>
        /// <param name="typeToConvert"></param>
        /// <param name="jsonSerializerOptions"></param>
        /// <returns></returns>
        /// <exception cref="JsonException"></exception>
        public override EnumTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions)
        {
            int currentDepth = utf8JsonReader.CurrentDepth;

            if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray)
                throw new JsonException();

            JsonTokenType startingTokenType = utf8JsonReader.TokenType;

            Option<EnumTestEnumString?> enumStringRequired = default;
            Option<EnumTestEnumInteger?> enumInteger = default;
            Option<EnumTestEnumIntegerOnly?> enumIntegerOnly = default;
            Option<TestEnumParametersEnumQueryDoubleParameter?> enumNumber = default;
            Option<EnumTestEnumString?> enumString = default;
            Option<OuterEnum?> outerEnum = default;
            Option<OuterEnumDefaultValue?> outerEnumDefaultValue = default;
            Option<OuterEnumInteger?> outerEnumInteger = default;
            Option<OuterEnumIntegerDefaultValue?> outerEnumIntegerDefaultValue = default;

            while (utf8JsonReader.Read())
            {
                if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth)
                    break;

                if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth)
                    break;

                if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1)
                {
                    string localVarJsonPropertyName = utf8JsonReader.GetString();
                    utf8JsonReader.Read();

                    switch (localVarJsonPropertyName)
                    {
                        case "enum_string_required":
                            string enumStringRequiredRawValue = utf8JsonReader.GetString();
                            if (enumStringRequiredRawValue != null)
                                enumStringRequired = new Option<EnumTestEnumString?>(EnumTestEnumStringValueConverter.FromStringOrDefault(enumStringRequiredRawValue));
                            break;
                        case "enum_integer":
                            string enumIntegerRawValue = utf8JsonReader.GetString();
                            if (enumIntegerRawValue != null)
                                enumInteger = new Option<EnumTestEnumInteger?>(EnumTestEnumIntegerValueConverter.FromStringOrDefault(enumIntegerRawValue));
                            break;
                        case "enum_integer_only":
                            string enumIntegerOnlyRawValue = utf8JsonReader.GetString();
                            if (enumIntegerOnlyRawValue != null)
                                enumIntegerOnly = new Option<EnumTestEnumIntegerOnly?>(EnumTestEnumIntegerOnlyValueConverter.FromStringOrDefault(enumIntegerOnlyRawValue));
                            break;
                        case "enum_number":
                            string enumNumberRawValue = utf8JsonReader.GetString();
                            if (enumNumberRawValue != null)
                                enumNumber = new Option<TestEnumParametersEnumQueryDoubleParameter?>(TestEnumParametersEnumQueryDoubleParameterValueConverter.FromStringOrDefault(enumNumberRawValue));
                            break;
                        case "enum_string":
                            string enumStringRawValue = utf8JsonReader.GetString();
                            if (enumStringRawValue != null)
                                enumString = new Option<EnumTestEnumString?>(EnumTestEnumStringValueConverter.FromStringOrDefault(enumStringRawValue));
                            break;
                        case "outerEnum":
                            string outerEnumRawValue = utf8JsonReader.GetString();
                            if (outerEnumRawValue != null)
                                outerEnum = new Option<OuterEnum?>(OuterEnumValueConverter.FromStringOrDefault(outerEnumRawValue));
                            break;
                        case "outerEnumDefaultValue":
                            string outerEnumDefaultValueRawValue = utf8JsonReader.GetString();
                            if (outerEnumDefaultValueRawValue != null)
                                outerEnumDefaultValue = new Option<OuterEnumDefaultValue?>(OuterEnumDefaultValueValueConverter.FromStringOrDefault(outerEnumDefaultValueRawValue));
                            break;
                        case "outerEnumInteger":
                            string outerEnumIntegerRawValue = utf8JsonReader.GetString();
                            if (outerEnumIntegerRawValue != null)
                                outerEnumInteger = new Option<OuterEnumInteger?>(OuterEnumIntegerValueConverter.FromStringOrDefault(outerEnumIntegerRawValue));
                            break;
                        case "outerEnumIntegerDefaultValue":
                            string outerEnumIntegerDefaultValueRawValue = utf8JsonReader.GetString();
                            if (outerEnumIntegerDefaultValueRawValue != null)
                                outerEnumIntegerDefaultValue = new Option<OuterEnumIntegerDefaultValue?>(OuterEnumIntegerDefaultValueValueConverter.FromStringOrDefault(outerEnumIntegerDefaultValueRawValue));
                            break;
                        default:
                            break;
                    }
                }
            }

            if (!enumStringRequired.IsSet)
                throw new ArgumentException("Property is required for class EnumTest.", nameof(enumStringRequired));

            if (enumStringRequired.IsSet && enumStringRequired.Value == null)
                throw new ArgumentNullException(nameof(enumStringRequired), "Property is not nullable for class EnumTest.");

            if (enumInteger.IsSet && enumInteger.Value == null)
                throw new ArgumentNullException(nameof(enumInteger), "Property is not nullable for class EnumTest.");

            if (enumIntegerOnly.IsSet && enumIntegerOnly.Value == null)
                throw new ArgumentNullException(nameof(enumIntegerOnly), "Property is not nullable for class EnumTest.");

            if (enumNumber.IsSet && enumNumber.Value == null)
                throw new ArgumentNullException(nameof(enumNumber), "Property is not nullable for class EnumTest.");

            if (enumString.IsSet && enumString.Value == null)
                throw new ArgumentNullException(nameof(enumString), "Property is not nullable for class EnumTest.");

            if (outerEnumDefaultValue.IsSet && outerEnumDefaultValue.Value == null)
                throw new ArgumentNullException(nameof(outerEnumDefaultValue), "Property is not nullable for class EnumTest.");

            if (outerEnumInteger.IsSet && outerEnumInteger.Value == null)
                throw new ArgumentNullException(nameof(outerEnumInteger), "Property is not nullable for class EnumTest.");

            if (outerEnumIntegerDefaultValue.IsSet && outerEnumIntegerDefaultValue.Value == null)
                throw new ArgumentNullException(nameof(outerEnumIntegerDefaultValue), "Property is not nullable for class EnumTest.");

            return new EnumTest(enumStringRequired.Value.Value, enumInteger, enumIntegerOnly, enumNumber, enumString, outerEnum, outerEnumDefaultValue, outerEnumInteger, outerEnumIntegerDefaultValue);
        }

        /// <summary>
        /// Serializes a <see cref="EnumTest" />
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="enumTest"></param>
        /// <param name="jsonSerializerOptions"></param>
        /// <exception cref="NotImplementedException"></exception>
        public override void Write(Utf8JsonWriter writer, EnumTest enumTest, JsonSerializerOptions jsonSerializerOptions)
        {
            writer.WriteStartObject();

            WriteProperties(writer, enumTest, jsonSerializerOptions);
            writer.WriteEndObject();
        }

        /// <summary>
        /// Serializes the properties of <see cref="EnumTest" />
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="enumTest"></param>
        /// <param name="jsonSerializerOptions"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void WriteProperties(Utf8JsonWriter writer, EnumTest enumTest, JsonSerializerOptions jsonSerializerOptions)
        {
            var enumStringRequiredRawValue = EnumTestEnumStringValueConverter.ToJsonValue(enumTest.EnumStringRequired);
            writer.WriteString("enum_string_required", enumStringRequiredRawValue);

            if (enumTest.EnumIntegerOption.IsSet)
            {
                var enumIntegerRawValue = EnumTestEnumIntegerValueConverter.ToJsonValue(enumTest.EnumInteger.Value);
                writer.WriteNumber("enum_integer", enumIntegerRawValue);
            }
            if (enumTest.EnumIntegerOnlyOption.IsSet)
            {
                var enumIntegerOnlyRawValue = EnumTestEnumIntegerOnlyValueConverter.ToJsonValue(enumTest.EnumIntegerOnly.Value);
                writer.WriteNumber("enum_integer_only", enumIntegerOnlyRawValue);
            }
            if (enumTest.EnumNumberOption.IsSet)
            {
                var enumNumberRawValue = TestEnumParametersEnumQueryDoubleParameterValueConverter.ToJsonValue(enumTest.EnumNumber.Value);
                writer.WriteNumber("enum_number", enumNumberRawValue);
            }
            if (enumTest.EnumStringOption.IsSet)
            {
                var enumStringRawValue = EnumTestEnumStringValueConverter.ToJsonValue(enumTest.EnumString.Value);
                writer.WriteString("enum_string", enumStringRawValue);
            }
            if (enumTest.OuterEnumOption.IsSet)
                if (enumTest.OuterEnumOption.Value != null)
                {
                    var outerEnumRawValue = OuterEnumValueConverter.ToJsonValue(enumTest.OuterEnumOption.Value.Value);
                    writer.WriteString("outerEnum", outerEnumRawValue);
                }
                else
                    writer.WriteNull("outerEnum");
            if (enumTest.OuterEnumDefaultValueOption.IsSet)
            {
                var outerEnumDefaultValueRawValue = OuterEnumDefaultValueValueConverter.ToJsonValue(enumTest.OuterEnumDefaultValue.Value);
                writer.WriteString("outerEnumDefaultValue", outerEnumDefaultValueRawValue);
            }
            if (enumTest.OuterEnumIntegerOption.IsSet)
            {
                var outerEnumIntegerRawValue = OuterEnumIntegerValueConverter.ToJsonValue(enumTest.OuterEnumInteger.Value);
                writer.WriteNumber("outerEnumInteger", outerEnumIntegerRawValue);
            }
            if (enumTest.OuterEnumIntegerDefaultValueOption.IsSet)
            {
                var outerEnumIntegerDefaultValueRawValue = OuterEnumIntegerDefaultValueValueConverter.ToJsonValue(enumTest.OuterEnumIntegerDefaultValue.Value);
                writer.WriteNumber("outerEnumIntegerDefaultValue", outerEnumIntegerDefaultValueRawValue);
            }
        }
    }
}
