using System.Text.Json.Serialization;

namespace StellaOps.Feedser.Source.Cve.Internal;

internal sealed record CveRecordDto
{
    [JsonPropertyName("cveId")]
    public string CveId { get; init; } = string.Empty;

    [JsonPropertyName("title")]
    public string? Title { get; init; }

    [JsonPropertyName("summary")]
    public string? Summary { get; init; }

    [JsonPropertyName("language")]
    public string? Language { get; init; }

    [JsonPropertyName("state")]
    public string State { get; init; } = "PUBLISHED";

    [JsonPropertyName("published")]
    public DateTimeOffset? Published { get; init; }

    [JsonPropertyName("modified")]
    public DateTimeOffset? Modified { get; init; }

    [JsonPropertyName("aliases")]
    public IReadOnlyList<string> Aliases { get; init; } = Array.Empty<string>();

    [JsonPropertyName("references")]
    public IReadOnlyList<CveReferenceDto> References { get; init; } = Array.Empty<CveReferenceDto>();

    [JsonPropertyName("affected")]
    public IReadOnlyList<CveAffectedDto> Affected { get; init; } = Array.Empty<CveAffectedDto>();

    [JsonPropertyName("metrics")]
    public IReadOnlyList<CveCvssMetricDto> Metrics { get; init; } = Array.Empty<CveCvssMetricDto>();
}

internal sealed record CveReferenceDto
{
    [JsonPropertyName("url")]
    public string Url { get; init; } = string.Empty;

    [JsonPropertyName("source")]
    public string? Source { get; init; }

    [JsonPropertyName("tags")]
    public IReadOnlyList<string> Tags { get; init; } = Array.Empty<string>();
}

internal sealed record CveAffectedDto
{
    [JsonPropertyName("vendor")]
    public string? Vendor { get; init; }

    [JsonPropertyName("product")]
    public string? Product { get; init; }

    [JsonPropertyName("platform")]
    public string? Platform { get; init; }

    [JsonPropertyName("defaultStatus")]
    public string? DefaultStatus { get; init; }

    [JsonPropertyName("versions")]
    public IReadOnlyList<CveVersionDto> Versions { get; init; } = Array.Empty<CveVersionDto>();
}

internal sealed record CveVersionDto
{
    [JsonPropertyName("status")]
    public string? Status { get; init; }

    [JsonPropertyName("version")]
    public string? Version { get; init; }

    [JsonPropertyName("lessThan")]
    public string? LessThan { get; init; }

    [JsonPropertyName("lessThanOrEqual")]
    public string? LessThanOrEqual { get; init; }

    [JsonPropertyName("versionType")]
    public string? VersionType { get; init; }

    [JsonPropertyName("versionRange")]
    public string? Range { get; init; }
}

internal sealed record CveCvssMetricDto
{
    [JsonPropertyName("version")]
    public string? Version { get; init; }

    [JsonPropertyName("vector")]
    public string? Vector { get; init; }

    [JsonPropertyName("baseScore")]
    public double? BaseScore { get; init; }

    [JsonPropertyName("baseSeverity")]
    public string? BaseSeverity { get; init; }
}
