using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

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

public sealed record MsrcVulnerabilityDetailDto
{
    [JsonPropertyName("id")]
    public string Id { get; init; } = string.Empty;

    [JsonPropertyName("vulnerabilityId")]
    public string VulnerabilityId { get; init; } = string.Empty;

    [JsonPropertyName("cveNumber")]
    public string? CveNumber { get; init; }

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

    [JsonPropertyName("title")]
    public string Title { get; init; } = string.Empty;

    [JsonPropertyName("description")]
    public string? Description { get; init; }

    [JsonPropertyName("releaseDate")]
    public DateTimeOffset? ReleaseDate { get; init; }

    [JsonPropertyName("lastModifiedDate")]
    public DateTimeOffset? LastModifiedDate { get; init; }

    [JsonPropertyName("severity")]
    public string? Severity { get; init; }

    [JsonPropertyName("threats")]
    public IReadOnlyList<MsrcThreatDto> Threats { get; init; } = Array.Empty<MsrcThreatDto>();

    [JsonPropertyName("remediations")]
    public IReadOnlyList<MsrcRemediationDto> Remediations { get; init; } = Array.Empty<MsrcRemediationDto>();

    [JsonPropertyName("affectedProducts")]
    public IReadOnlyList<MsrcAffectedProductDto> AffectedProducts { get; init; } = Array.Empty<MsrcAffectedProductDto>();

    [JsonPropertyName("cvssV3")]
    public MsrcCvssDto? Cvss { get; init; }

    [JsonPropertyName("releaseNoteUrl")]
    public string? ReleaseNoteUrl { get; init; }

    [JsonPropertyName("cvrfUrl")]
    public string? CvrfUrl { get; init; }
}

public sealed record MsrcThreatDto
{
    [JsonPropertyName("type")]
    public string? Type { get; init; }

    [JsonPropertyName("description")]
    public string? Description { get; init; }

    [JsonPropertyName("severity")]
    public string? Severity { get; init; }
}

public sealed record MsrcRemediationDto
{
    [JsonPropertyName("id")]
    public string? Id { get; init; }

    [JsonPropertyName("type")]
    public string? Type { get; init; }

    [JsonPropertyName("description")]
    public string? Description { get; init; }

    [JsonPropertyName("url")]
    public string? Url { get; init; }

    [JsonPropertyName("kbNumber")]
    public string? KbNumber { get; init; }
}

public sealed record MsrcAffectedProductDto
{
    [JsonPropertyName("productId")]
    public string? ProductId { get; init; }

    [JsonPropertyName("productName")]
    public string? ProductName { get; init; }

    [JsonPropertyName("cpe")]
    public string? Cpe { get; init; }

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

    [JsonPropertyName("architecture")]
    public string? Architecture { get; init; }

    [JsonPropertyName("buildNumber")]
    public string? BuildNumber { get; init; }
}

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

    [JsonPropertyName("vectorString")]
    public string? VectorString { get; init; }
}
