using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.Json;

namespace OpenAI.Embeddings;

[CodeGenType("CreateEmbeddingResponse")]
[CodeGenSuppress("Data")]
[CodeGenSuppress(nameof(OpenAIEmbeddingCollection))]
[CodeGenSuppress(nameof(OpenAIEmbeddingCollection), typeof(string), typeof(EmbeddingTokenUsage))]
[CodeGenSuppress(nameof(OpenAIEmbeddingCollection), typeof(string), typeof(EmbeddingTokenUsage),  typeof(string), typeof(IDictionary<string, BinaryData>))]
public partial class OpenAIEmbeddingCollection : ReadOnlyCollection<OpenAIEmbedding>
{
    // CUSTOM: Made private. This property does not add value in the context of a strongly-typed class.
    /// <summary> The object type, which is always "list". </summary>
    [CodeGenMember("Object")]
    private string Object { get; } = "list";

    // CUSTOM: Set the inherited Items property via the base constructor in favor of the suppressed Data property.
    /// <summary> Initializes a new instance of <see cref="OpenAIEmbeddingCollection"/>. </summary>
    /// <param name="data"> The list of embeddings generated by the model. </param>
    /// <param name="model"> The name of the model used to generate the embedding. </param>
    /// <param name="usage"> The usage information for the request. </param>
    /// <exception cref="ArgumentNullException"> <paramref name="data"/>, <paramref name="model"/> or <paramref name="usage"/> is null. </exception>
    internal OpenAIEmbeddingCollection(IEnumerable<OpenAIEmbedding> data, string model, EmbeddingTokenUsage usage)
        : base([.. data])
    {
        Argument.AssertNotNull(data, nameof(data));
        Argument.AssertNotNull(model, nameof(model));
        Argument.AssertNotNull(usage, nameof(usage));

        Model = model;
        Usage = usage;
    }

    // CUSTOM: Set the inherited Items property via the base constructor in favor of the suppressed Data property.
    /// <summary> Initializes a new instance of <see cref="OpenAIEmbeddingCollection"/>. </summary>
    /// <param name="data"> The list of embeddings generated by the model. </param>
    /// <param name="model"> The name of the model used to generate the embedding. </param>
    /// <param name="object"> The object type, which is always "list". </param>
    /// <param name="usage"> The usage information for the request. </param>
    /// <param name="serializedAdditionalRawData"> Keeps track of any properties unknown to the library. </param>
    internal OpenAIEmbeddingCollection(IReadOnlyList<OpenAIEmbedding> data, string model, string @object, EmbeddingTokenUsage usage, IDictionary<string, BinaryData> serializedAdditionalRawData)
        : base([.. data])
    {
        Model = model;
        Object = @object;
        Usage = usage;
        _additionalBinaryDataProperties = serializedAdditionalRawData;
    }

    // CUSTOM: Set the inherited Items property via the base constructor in favor of the suppressed Data property.
    /// <summary> Initializes a new instance of <see cref="OpenAIEmbeddingCollection"/> for deserialization. </summary>
    internal OpenAIEmbeddingCollection()
        : base([])
    {
    }

    internal static OpenAIEmbeddingCollection FromClientResult(ClientResult result)
    {
        using PipelineResponse response = result.GetRawResponse();
        using JsonDocument document = JsonDocument.Parse(response.Content);
        return DeserializeOpenAIEmbeddingCollection(document.RootElement, ModelSerializationExtensions.WireOptions);
    }
}