// <auto-generated>
/*
 * API ebike_v1 1.0.0
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 1.0.0
 * Generated by: https://github.com/openapitools/openapi-generator.git
 */

#nullable enable

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 Org.OpenAPITools.Client;

namespace Org.OpenAPITools.Model
{
    /// <summary>
    /// Rider
    /// </summary>
    public partial class Rider : IValidatableObject
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Rider" /> class.
        /// </summary>
        /// <param name="age">The age of the rider in years</param>
        /// <param name="cadence">The comfortable cadence of the rider in rpm</param>
        /// <param name="height">The height of the rider in cm</param>
        /// <param name="name">The name of the rider</param>
        /// <param name="power">The the pedaling performance of the rider in W</param>
        /// <param name="weight">The weight of the rider in kg</param>
        /// <param name="id">id (default to 0)</param>
        [JsonConstructor]
        public Rider(int age, int cadence, int height, string name, int power, int weight, Option<int?> id = default)
        {
            Age = age;
            Cadence = cadence;
            Height = height;
            Name = name;
            Power = power;
            Weight = weight;
            IdOption = id;
            OnCreated();
        }

        partial void OnCreated();

        /// <summary>
        /// The age of the rider in years
        /// </summary>
        /// <value>The age of the rider in years</value>
        [JsonPropertyName("age")]
        public int Age { get; set; }

        /// <summary>
        /// The comfortable cadence of the rider in rpm
        /// </summary>
        /// <value>The comfortable cadence of the rider in rpm</value>
        [JsonPropertyName("cadence")]
        public int Cadence { get; set; }

        /// <summary>
        /// The height of the rider in cm
        /// </summary>
        /// <value>The height of the rider in cm</value>
        [JsonPropertyName("height")]
        public int Height { get; set; }

        /// <summary>
        /// The name of the rider
        /// </summary>
        /// <value>The name of the rider</value>
        [JsonPropertyName("name")]
        public string Name { get; set; }

        /// <summary>
        /// The the pedaling performance of the rider in W
        /// </summary>
        /// <value>The the pedaling performance of the rider in W</value>
        [JsonPropertyName("power")]
        public int Power { get; set; }

        /// <summary>
        /// The weight of the rider in kg
        /// </summary>
        /// <value>The weight of the rider in kg</value>
        [JsonPropertyName("weight")]
        public int Weight { get; set; }

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

        /// <summary>
        /// Gets or Sets Id
        /// </summary>
        [JsonPropertyName("id")]
        public int? Id { get { return this.IdOption.Value; } set { this.IdOption = new(value); } }

        /// <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 Rider {\n");
            sb.Append("  Age: ").Append(Age).Append("\n");
            sb.Append("  Cadence: ").Append(Cadence).Append("\n");
            sb.Append("  Height: ").Append(Height).Append("\n");
            sb.Append("  Name: ").Append(Name).Append("\n");
            sb.Append("  Power: ").Append(Power).Append("\n");
            sb.Append("  Weight: ").Append(Weight).Append("\n");
            sb.Append("  Id: ").Append(Id).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<ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
        {
            yield break;
        }
    }

    /// <summary>
    /// A Json converter for type <see cref="Rider" />
    /// </summary>
    public class RiderJsonConverter : JsonConverter<Rider>
    {
        /// <summary>
        /// Deserializes json to <see cref="Rider" />
        /// </summary>
        /// <param name="utf8JsonReader"></param>
        /// <param name="typeToConvert"></param>
        /// <param name="jsonSerializerOptions"></param>
        /// <returns></returns>
        /// <exception cref="JsonException"></exception>
        public override Rider 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<int?> age = default;
            Option<int?> cadence = default;
            Option<int?> height = default;
            Option<string?> name = default;
            Option<int?> power = default;
            Option<int?> weight = default;
            Option<int?> id = 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 "age":
                            age = new Option<int?>(utf8JsonReader.TokenType == JsonTokenType.Null ? (int?)null : utf8JsonReader.GetInt32());
                            break;
                        case "cadence":
                            cadence = new Option<int?>(utf8JsonReader.TokenType == JsonTokenType.Null ? (int?)null : utf8JsonReader.GetInt32());
                            break;
                        case "height":
                            height = new Option<int?>(utf8JsonReader.TokenType == JsonTokenType.Null ? (int?)null : utf8JsonReader.GetInt32());
                            break;
                        case "name":
                            name = new Option<string?>(utf8JsonReader.GetString()!);
                            break;
                        case "power":
                            power = new Option<int?>(utf8JsonReader.TokenType == JsonTokenType.Null ? (int?)null : utf8JsonReader.GetInt32());
                            break;
                        case "weight":
                            weight = new Option<int?>(utf8JsonReader.TokenType == JsonTokenType.Null ? (int?)null : utf8JsonReader.GetInt32());
                            break;
                        case "id":
                            id = new Option<int?>(utf8JsonReader.TokenType == JsonTokenType.Null ? (int?)null : utf8JsonReader.GetInt32());
                            break;
                        default:
                            break;
                    }
                }
            }

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

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

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

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

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

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

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

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

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

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

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

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

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

            return new Rider(age.Value!.Value!, cadence.Value!.Value!, height.Value!.Value!, name.Value!, power.Value!.Value!, weight.Value!.Value!, id);
        }

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

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

        /// <summary>
        /// Serializes the properties of <see cref="Rider" />
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="rider"></param>
        /// <param name="jsonSerializerOptions"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void WriteProperties(Utf8JsonWriter writer, Rider rider, JsonSerializerOptions jsonSerializerOptions)
        {
            if (rider.Name == null)
                throw new ArgumentNullException(nameof(rider.Name), "Property is required for class Rider.");

            writer.WriteNumber("age", rider.Age);

            writer.WriteNumber("cadence", rider.Cadence);

            writer.WriteNumber("height", rider.Height);

            writer.WriteString("name", rider.Name);

            writer.WriteNumber("power", rider.Power);

            writer.WriteNumber("weight", rider.Weight);

            if (rider.IdOption.IsSet)
                writer.WriteNumber("id", rider.IdOption.Value!.Value);
        }
    }
}
