using System.Text.Json.Serialization;

namespace StellaOps.Feedser.Source.Vndr.Chromium.Internal;

internal sealed record ChromiumDto(
    [property: JsonPropertyName("postId")] string PostId,
    [property: JsonPropertyName("title")] string Title,
    [property: JsonPropertyName("detailUrl")] string DetailUrl,
    [property: JsonPropertyName("published")] DateTimeOffset Published,
    [property: JsonPropertyName("updated")] DateTimeOffset? Updated,
    [property: JsonPropertyName("summary")] string? Summary,
    [property: JsonPropertyName("cves")] IReadOnlyList<string> Cves,
    [property: JsonPropertyName("platforms")] IReadOnlyList<string> Platforms,
    [property: JsonPropertyName("versions")] IReadOnlyList<ChromiumVersionInfo> Versions,
    [property: JsonPropertyName("references")] IReadOnlyList<ChromiumReference> References)
{
    public static ChromiumDto From(ChromiumDocumentMetadata metadata, IReadOnlyList<string> cves, IReadOnlyList<string> platforms, IReadOnlyList<ChromiumVersionInfo> versions, IReadOnlyList<ChromiumReference> references)
        => new(
            metadata.PostId,
            metadata.Title,
            metadata.DetailUrl.ToString(),
            metadata.Published,
            metadata.Updated,
            metadata.Summary,
            cves,
            platforms,
            versions,
            references);
}

internal sealed record ChromiumVersionInfo(
    [property: JsonPropertyName("platform")] string Platform,
    [property: JsonPropertyName("channel")] string Channel,
    [property: JsonPropertyName("version")] string Version);

internal sealed record ChromiumReference(
    [property: JsonPropertyName("url")] string Url,
    [property: JsonPropertyName("kind")] string Kind,
    [property: JsonPropertyName("label")] string? Label);
