// <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>
    /// Defines RequiredClass_required_nullable_enum_string
    /// </summary>
    public enum RequiredClassRequiredNullableEnumString
    {
        /// <summary>
        /// Enum UPPER for value: UPPER
        /// </summary>
        UPPER = 1,

        /// <summary>
        /// Enum Lower for value: lower
        /// </summary>
        Lower = 2,

        /// <summary>
        /// Enum Empty for value: 
        /// </summary>
        Empty = 3,

        /// <summary>
        /// Enum ValuewithTab for value: Value\twith tab
        /// </summary>
        ValuewithTab = 4,

        /// <summary>
        /// Enum ValueWithQuote for value: Value with \&quot; quote
        /// </summary>
        ValueWithQuote = 5,

        /// <summary>
        /// Enum ValueWithEscapedQuote for value: Value with escaped \&quot; quote
        /// </summary>
        ValueWithEscapedQuote = 6,

        /// <summary>
        /// Enum Duplicatevalue for value: Duplicate\nvalue
        /// </summary>
        Duplicatevalue = 7,

        /// <summary>
        /// Enum Duplicatevalue2 for value: Duplicate\r\nvalue
        /// </summary>
        Duplicatevalue2 = 8
    }

    /// <summary>
    /// Converts <see cref="RequiredClassRequiredNullableEnumString"/> to and from the JSON value
    /// </summary>
    public static class RequiredClassRequiredNullableEnumStringValueConverter
    {
        /// <summary>
        /// Parses a given value to <see cref="RequiredClassRequiredNullableEnumString"/>
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static RequiredClassRequiredNullableEnumString FromString(string value)
        {
            if (value.Equals("UPPER"))
                return RequiredClassRequiredNullableEnumString.UPPER;

            if (value.Equals("lower"))
                return RequiredClassRequiredNullableEnumString.Lower;

            if (value.Equals(""))
                return RequiredClassRequiredNullableEnumString.Empty;

            if (value.Equals("Value\twith tab"))
                return RequiredClassRequiredNullableEnumString.ValuewithTab;

            if (value.Equals("Value with \" quote"))
                return RequiredClassRequiredNullableEnumString.ValueWithQuote;

            if (value.Equals("Value with escaped \" quote"))
                return RequiredClassRequiredNullableEnumString.ValueWithEscapedQuote;

            if (value.Equals("Duplicate\nvalue"))
                return RequiredClassRequiredNullableEnumString.Duplicatevalue;

            if (value.Equals("Duplicate\r\nvalue"))
                return RequiredClassRequiredNullableEnumString.Duplicatevalue2;

            throw new NotImplementedException($"Could not convert value to type RequiredClassRequiredNullableEnumString: '{value}'");
        }

        /// <summary>
        /// Parses a given value to <see cref="RequiredClassRequiredNullableEnumString"/>
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static RequiredClassRequiredNullableEnumString? FromStringOrDefault(string value)
        {
            if (value.Equals("UPPER"))
                return RequiredClassRequiredNullableEnumString.UPPER;

            if (value.Equals("lower"))
                return RequiredClassRequiredNullableEnumString.Lower;

            if (value.Equals(""))
                return RequiredClassRequiredNullableEnumString.Empty;

            if (value.Equals("Value\twith tab"))
                return RequiredClassRequiredNullableEnumString.ValuewithTab;

            if (value.Equals("Value with \" quote"))
                return RequiredClassRequiredNullableEnumString.ValueWithQuote;

            if (value.Equals("Value with escaped \" quote"))
                return RequiredClassRequiredNullableEnumString.ValueWithEscapedQuote;

            if (value.Equals("Duplicate\nvalue"))
                return RequiredClassRequiredNullableEnumString.Duplicatevalue;

            if (value.Equals("Duplicate\r\nvalue"))
                return RequiredClassRequiredNullableEnumString.Duplicatevalue2;

            return null;
        }

        /// <summary>
        /// Converts the <see cref="RequiredClassRequiredNullableEnumString"/> to the json value
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public static string ToJsonValue(RequiredClassRequiredNullableEnumString value)
        {
            if (value == RequiredClassRequiredNullableEnumString.UPPER)
                return "UPPER";

            if (value == RequiredClassRequiredNullableEnumString.Lower)
                return "lower";

            if (value == RequiredClassRequiredNullableEnumString.Empty)
                return "";

            if (value == RequiredClassRequiredNullableEnumString.ValuewithTab)
                return "Value\twith tab";

            if (value == RequiredClassRequiredNullableEnumString.ValueWithQuote)
                return "Value with \" quote";

            if (value == RequiredClassRequiredNullableEnumString.ValueWithEscapedQuote)
                return "Value with escaped \" quote";

            if (value == RequiredClassRequiredNullableEnumString.Duplicatevalue)
                return "Duplicate\nvalue";

            if (value == RequiredClassRequiredNullableEnumString.Duplicatevalue2)
                return "Duplicate\r\nvalue";

            throw new NotImplementedException($"Value could not be handled: '{value}'");
        }
    }

    /// <summary>
    /// A Json converter for type <see cref="RequiredClassRequiredNullableEnumString"/>
    /// </summary>
    /// <exception cref="NotImplementedException"></exception>
    public class RequiredClassRequiredNullableEnumStringJsonConverter : JsonConverter<RequiredClassRequiredNullableEnumString>
    {
        /// <summary>
        /// Returns a  from the Json object
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="typeToConvert"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public override RequiredClassRequiredNullableEnumString Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            string rawValue = reader.GetString();

            RequiredClassRequiredNullableEnumString? result = rawValue == null
                ? null
                : RequiredClassRequiredNullableEnumStringValueConverter.FromStringOrDefault(rawValue);

            if (result != null)
                return result.Value;

            throw new JsonException();
        }

        /// <summary>
        /// Writes the RequiredClassRequiredNullableEnumString to the json writer
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="requiredClassRequiredNullableEnumString"></param>
        /// <param name="options"></param>
        public override void Write(Utf8JsonWriter writer, RequiredClassRequiredNullableEnumString requiredClassRequiredNullableEnumString, JsonSerializerOptions options)
        {
            writer.WriteStringValue(requiredClassRequiredNullableEnumString.ToString());
        }
    }

    /// <summary>
    /// A Json converter for type <see cref="RequiredClassRequiredNullableEnumString"/>
    /// </summary>
    public class RequiredClassRequiredNullableEnumStringNullableJsonConverter : JsonConverter<RequiredClassRequiredNullableEnumString?>
    {
        /// <summary>
        /// Returns a RequiredClassRequiredNullableEnumString from the Json object
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="typeToConvert"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public override RequiredClassRequiredNullableEnumString? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            string rawValue = reader.GetString();

            RequiredClassRequiredNullableEnumString? result = rawValue == null
                ? null
                : RequiredClassRequiredNullableEnumStringValueConverter.FromStringOrDefault(rawValue);

            if (result != null)
                return result.Value;

            throw new JsonException();
        }

        /// <summary>
        /// Writes the DateTime to the json writer
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="requiredClassRequiredNullableEnumString"></param>
        /// <param name="options"></param>
        public override void Write(Utf8JsonWriter writer, RequiredClassRequiredNullableEnumString? requiredClassRequiredNullableEnumString, JsonSerializerOptions options)
        {
            writer.WriteStringValue(requiredClassRequiredNullableEnumString?.ToString() ?? "null");
        }
    }
}
