|
| 1 | +// <auto-generated/> |
| 2 | + |
| 3 | +#nullable disable |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.ClientModel.Primitives; |
| 7 | +using System.Collections.Generic; |
| 8 | +using System.Text.Json; |
| 9 | +using OpenAI; |
| 10 | + |
| 11 | +namespace OpenAI.Videos |
| 12 | +{ |
| 13 | + internal partial class InternaVideoItemCollectionOptions : IJsonModel<InternaVideoItemCollectionOptions> |
| 14 | + { |
| 15 | + void IJsonModel<InternaVideoItemCollectionOptions>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) |
| 16 | + { |
| 17 | + writer.WriteStartObject(); |
| 18 | + JsonModelWriteCore(writer, options); |
| 19 | + writer.WriteEndObject(); |
| 20 | + } |
| 21 | + |
| 22 | + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) |
| 23 | + { |
| 24 | + string format = options.Format == "W" ? ((IPersistableModel<InternaVideoItemCollectionOptions>)this).GetFormatFromOptions(options) : options.Format; |
| 25 | + if (format != "J") |
| 26 | + { |
| 27 | + throw new FormatException($"The model {nameof(InternaVideoItemCollectionOptions)} does not support writing '{format}' format."); |
| 28 | + } |
| 29 | + // Plugin customization: remove options.Format != "W" check |
| 30 | + if (_additionalBinaryDataProperties != null) |
| 31 | + { |
| 32 | + foreach (var item in _additionalBinaryDataProperties) |
| 33 | + { |
| 34 | + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) |
| 35 | + { |
| 36 | + continue; |
| 37 | + } |
| 38 | + writer.WritePropertyName(item.Key); |
| 39 | +#if NET6_0_OR_GREATER |
| 40 | + writer.WriteRawValue(item.Value); |
| 41 | +#else |
| 42 | + using (JsonDocument document = JsonDocument.Parse(item.Value)) |
| 43 | + { |
| 44 | + JsonSerializer.Serialize(writer, document.RootElement); |
| 45 | + } |
| 46 | +#endif |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + InternaVideoItemCollectionOptions IJsonModel<InternaVideoItemCollectionOptions>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); |
| 52 | + |
| 53 | + protected virtual InternaVideoItemCollectionOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) |
| 54 | + { |
| 55 | + string format = options.Format == "W" ? ((IPersistableModel<InternaVideoItemCollectionOptions>)this).GetFormatFromOptions(options) : options.Format; |
| 56 | + if (format != "J") |
| 57 | + { |
| 58 | + throw new FormatException($"The model {nameof(InternaVideoItemCollectionOptions)} does not support reading '{format}' format."); |
| 59 | + } |
| 60 | + using JsonDocument document = JsonDocument.ParseValue(ref reader); |
| 61 | + return DeserializeInternaVideoItemCollectionOptions(document.RootElement, options); |
| 62 | + } |
| 63 | + |
| 64 | + internal static InternaVideoItemCollectionOptions DeserializeInternaVideoItemCollectionOptions(JsonElement element, ModelReaderWriterOptions options) |
| 65 | + { |
| 66 | + if (element.ValueKind == JsonValueKind.Null) |
| 67 | + { |
| 68 | + return null; |
| 69 | + } |
| 70 | + string afterId = default; |
| 71 | + int? pageSizeLimit = default; |
| 72 | + InternalVideoItemCollectionOrder? order = default; |
| 73 | + IDictionary<string, BinaryData> additionalBinaryDataProperties = new ChangeTrackingDictionary<string, BinaryData>(); |
| 74 | + foreach (var prop in element.EnumerateObject()) |
| 75 | + { |
| 76 | + // Plugin customization: remove options.Format != "W" check |
| 77 | + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); |
| 78 | + } |
| 79 | + return new InternaVideoItemCollectionOptions(afterId, pageSizeLimit, order, additionalBinaryDataProperties); |
| 80 | + } |
| 81 | + |
| 82 | + BinaryData IPersistableModel<InternaVideoItemCollectionOptions>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); |
| 83 | + |
| 84 | + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) |
| 85 | + { |
| 86 | + string format = options.Format == "W" ? ((IPersistableModel<InternaVideoItemCollectionOptions>)this).GetFormatFromOptions(options) : options.Format; |
| 87 | + switch (format) |
| 88 | + { |
| 89 | + case "J": |
| 90 | + return ModelReaderWriter.Write(this, options, OpenAIContext.Default); |
| 91 | + default: |
| 92 | + throw new FormatException($"The model {nameof(InternaVideoItemCollectionOptions)} does not support writing '{options.Format}' format."); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + InternaVideoItemCollectionOptions IPersistableModel<InternaVideoItemCollectionOptions>.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); |
| 97 | + |
| 98 | + protected virtual InternaVideoItemCollectionOptions PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) |
| 99 | + { |
| 100 | + string format = options.Format == "W" ? ((IPersistableModel<InternaVideoItemCollectionOptions>)this).GetFormatFromOptions(options) : options.Format; |
| 101 | + switch (format) |
| 102 | + { |
| 103 | + case "J": |
| 104 | + using (JsonDocument document = JsonDocument.Parse(data)) |
| 105 | + { |
| 106 | + return DeserializeInternaVideoItemCollectionOptions(document.RootElement, options); |
| 107 | + } |
| 108 | + default: |
| 109 | + throw new FormatException($"The model {nameof(InternaVideoItemCollectionOptions)} does not support reading '{options.Format}' format."); |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + string IPersistableModel<InternaVideoItemCollectionOptions>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; |
| 114 | + } |
| 115 | +} |
0 commit comments