//------------------------------------------------------------------------------ // // This code was generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. // // Changes to this file may cause incorrect behavior and will be lost when // the code is regenerated. // //------------------------------------------------------------------------------ #nullable enable namespace LukeHagar.PlexAPI.SDK.Models.Requests { using LukeHagar.PlexAPI.SDK.Models.Requests; using LukeHagar.PlexAPI.SDK.Utils; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Numerics; using System.Reflection; public class GetLibrarySectionsAllOptimizedForStreamingType { private GetLibrarySectionsAllOptimizedForStreamingType(string value) { Value = value; } public string Value { get; private set; } public static GetLibrarySectionsAllOptimizedForStreamingType GetLibrarySectionsAllOptimizedForStreaming1 { get { return new GetLibrarySectionsAllOptimizedForStreamingType("get-library-sections-all_optimizedForStreaming_1"); } } public static GetLibrarySectionsAllOptimizedForStreamingType Boolean { get { return new GetLibrarySectionsAllOptimizedForStreamingType("boolean"); } } public static GetLibrarySectionsAllOptimizedForStreamingType Null { get { return new GetLibrarySectionsAllOptimizedForStreamingType("null"); } } public override string ToString() { return Value; } public static implicit operator String(GetLibrarySectionsAllOptimizedForStreamingType v) { return v.Value; } public static GetLibrarySectionsAllOptimizedForStreamingType FromString(string v) { switch(v) { case "get-library-sections-all_optimizedForStreaming_1": return GetLibrarySectionsAllOptimizedForStreaming1; case "boolean": return Boolean; case "null": return Null; default: throw new ArgumentException("Invalid value for GetLibrarySectionsAllOptimizedForStreamingType"); } } public override bool Equals(object? obj) { if (obj == null || GetType() != obj.GetType()) { return false; } return Value.Equals(((GetLibrarySectionsAllOptimizedForStreamingType)obj).Value); } public override int GetHashCode() { return Value.GetHashCode(); } } /// /// Has this media been optimized for streaming. NOTE: This can be 0, 1, false or true /// [JsonConverter(typeof(GetLibrarySectionsAllOptimizedForStreaming.GetLibrarySectionsAllOptimizedForStreamingConverter))] public class GetLibrarySectionsAllOptimizedForStreaming { public GetLibrarySectionsAllOptimizedForStreaming(GetLibrarySectionsAllOptimizedForStreamingType type) { Type = type; } [SpeakeasyMetadata("form:explode=true")] public GetLibrarySectionsAllOptimizedForStreaming1? GetLibrarySectionsAllOptimizedForStreaming1 { get; set; } [SpeakeasyMetadata("form:explode=true")] public bool? Boolean { get; set; } public GetLibrarySectionsAllOptimizedForStreamingType Type { get; set; } public static GetLibrarySectionsAllOptimizedForStreaming CreateGetLibrarySectionsAllOptimizedForStreaming1(GetLibrarySectionsAllOptimizedForStreaming1 getLibrarySectionsAllOptimizedForStreaming1) { GetLibrarySectionsAllOptimizedForStreamingType typ = GetLibrarySectionsAllOptimizedForStreamingType.GetLibrarySectionsAllOptimizedForStreaming1; GetLibrarySectionsAllOptimizedForStreaming res = new GetLibrarySectionsAllOptimizedForStreaming(typ); res.GetLibrarySectionsAllOptimizedForStreaming1 = getLibrarySectionsAllOptimizedForStreaming1; return res; } public static GetLibrarySectionsAllOptimizedForStreaming CreateBoolean(bool boolean) { GetLibrarySectionsAllOptimizedForStreamingType typ = GetLibrarySectionsAllOptimizedForStreamingType.Boolean; GetLibrarySectionsAllOptimizedForStreaming res = new GetLibrarySectionsAllOptimizedForStreaming(typ); res.Boolean = boolean; return res; } public static GetLibrarySectionsAllOptimizedForStreaming CreateNull() { GetLibrarySectionsAllOptimizedForStreamingType typ = GetLibrarySectionsAllOptimizedForStreamingType.Null; return new GetLibrarySectionsAllOptimizedForStreaming(typ); } public class GetLibrarySectionsAllOptimizedForStreamingConverter : JsonConverter { public override bool CanConvert(System.Type objectType) => objectType == typeof(GetLibrarySectionsAllOptimizedForStreaming); public override bool CanRead => true; public override object? ReadJson(JsonReader reader, System.Type objectType, object? existingValue, JsonSerializer serializer) { var json = JRaw.Create(reader).ToString(); if (json == "null") { return null; } var fallbackCandidates = new List<(System.Type, object, string)>(); try { return new GetLibrarySectionsAllOptimizedForStreaming(GetLibrarySectionsAllOptimizedForStreamingType.GetLibrarySectionsAllOptimizedForStreaming1) { GetLibrarySectionsAllOptimizedForStreaming1 = ResponseBodyDeserializer.DeserializeUndiscriminatedUnionMember(json) }; } catch (ResponseBodyDeserializer.MissingMemberException) { fallbackCandidates.Add((typeof(GetLibrarySectionsAllOptimizedForStreaming1), new GetLibrarySectionsAllOptimizedForStreaming(GetLibrarySectionsAllOptimizedForStreamingType.GetLibrarySectionsAllOptimizedForStreaming1), "GetLibrarySectionsAllOptimizedForStreaming1")); } catch (ResponseBodyDeserializer.DeserializationException) { // try next option } catch (Exception) { throw; } try { var converted = Convert.ToBoolean(json); return new GetLibrarySectionsAllOptimizedForStreaming(GetLibrarySectionsAllOptimizedForStreamingType.Boolean) { Boolean = converted }; } catch (System.FormatException) { // try next option } if (fallbackCandidates.Count > 0) { fallbackCandidates.Sort((a, b) => ResponseBodyDeserializer.CompareFallbackCandidates(a.Item1, b.Item1, json)); foreach(var (deserializationType, returnObject, propertyName) in fallbackCandidates) { try { return ResponseBodyDeserializer.DeserializeUndiscriminatedUnionFallback(deserializationType, returnObject, propertyName, json); } catch (ResponseBodyDeserializer.DeserializationException) { // try next fallback option } catch (Exception) { throw; } } } throw new InvalidOperationException("Could not deserialize into any supported types."); } public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) { if (value == null) { writer.WriteRawValue("null"); return; } GetLibrarySectionsAllOptimizedForStreaming res = (GetLibrarySectionsAllOptimizedForStreaming)value; if (GetLibrarySectionsAllOptimizedForStreamingType.FromString(res.Type).Equals(GetLibrarySectionsAllOptimizedForStreamingType.Null)) { writer.WriteRawValue("null"); return; } if (res.GetLibrarySectionsAllOptimizedForStreaming1 != null) { writer.WriteRawValue(Utilities.SerializeJSON(res.GetLibrarySectionsAllOptimizedForStreaming1)); return; } if (res.Boolean != null) { writer.WriteRawValue(Utilities.SerializeJSON(res.Boolean)); return; } } } } }