// <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 zebra_type
    /// </summary>
    public enum ZebraType
    {
        /// <summary>
        /// Enum Plains for value: plains
        /// </summary>
        Plains = 1,

        /// <summary>
        /// Enum Mountain for value: mountain
        /// </summary>
        Mountain = 2,

        /// <summary>
        /// Enum Grevys for value: grevys
        /// </summary>
        Grevys = 3
    }

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

            if (value.Equals("mountain"))
                return ZebraType.Mountain;

            if (value.Equals("grevys"))
                return ZebraType.Grevys;

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

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

            if (value.Equals("mountain"))
                return ZebraType.Mountain;

            if (value.Equals("grevys"))
                return ZebraType.Grevys;

            return null;
        }

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

            if (value == ZebraType.Mountain)
                return "mountain";

            if (value == ZebraType.Grevys)
                return "grevys";

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

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

            ZebraType? result = rawValue == null
                ? null
                : ZebraTypeValueConverter.FromStringOrDefault(rawValue);

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

            throw new JsonException();
        }

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

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

            ZebraType? result = rawValue == null
                ? null
                : ZebraTypeValueConverter.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="zebraType"></param>
        /// <param name="options"></param>
        public override void Write(Utf8JsonWriter writer, ZebraType? zebraType, JsonSerializerOptions options)
        {
            writer.WriteStringValue(zebraType?.ToString() ?? "null");
        }
    }
}
