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

namespace StellaOps.Scanner.WebService.Contracts;

public sealed record PolicyPreviewRequestDto
{
    [JsonPropertyName("imageDigest")]
    public string? ImageDigest { get; init; }

    [JsonPropertyName("findings")]
    public IReadOnlyList<PolicyPreviewFindingDto>? Findings { get; init; }

    [JsonPropertyName("baseline")]
    public IReadOnlyList<PolicyPreviewVerdictDto>? Baseline { get; init; }

    [JsonPropertyName("policy")]
    public PolicyPreviewPolicyDto? Policy { get; init; }
}

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

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

    [JsonPropertyName("environment")]
    public string? Environment { get; init; }

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

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

    [JsonPropertyName("license")]
    public string? License { get; init; }

    [JsonPropertyName("image")]
    public string? Image { get; init; }

    [JsonPropertyName("repository")]
    public string? Repository { get; init; }

    [JsonPropertyName("package")]
    public string? Package { get; init; }

    [JsonPropertyName("purl")]
    public string? Purl { get; init; }

    [JsonPropertyName("cve")]
    public string? Cve { get; init; }

    [JsonPropertyName("path")]
    public string? Path { get; init; }

    [JsonPropertyName("layerDigest")]
    public string? LayerDigest { get; init; }

    [JsonPropertyName("tags")]
    public IReadOnlyList<string>? Tags { get; init; }
}

public sealed record PolicyPreviewVerdictDto
{
    [JsonPropertyName("findingId")]
    public string? FindingId { get; init; }

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

    [JsonPropertyName("ruleName")]
    public string? RuleName { get; init; }

    [JsonPropertyName("ruleAction")]
    public string? RuleAction { get; init; }

    [JsonPropertyName("notes")]
    public string? Notes { get; init; }

    [JsonPropertyName("score")]
    public double? Score { get; init; }

    [JsonPropertyName("configVersion")]
    public string? ConfigVersion { get; init; }

    [JsonPropertyName("inputs")]
    public IReadOnlyDictionary<string, double>? Inputs { get; init; }

    [JsonPropertyName("quietedBy")]
    public string? QuietedBy { get; init; }

    [JsonPropertyName("quiet")]
    public bool? Quiet { get; init; }
}

public sealed record PolicyPreviewPolicyDto
{
    [JsonPropertyName("content")]
    public string? Content { get; init; }

    [JsonPropertyName("format")]
    public string? Format { get; init; }

    [JsonPropertyName("actor")]
    public string? Actor { get; init; }

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

public sealed record PolicyPreviewResponseDto
{
    [JsonPropertyName("success")]
    public bool Success { get; init; }

    [JsonPropertyName("policyDigest")]
    public string? PolicyDigest { get; init; }

    [JsonPropertyName("revisionId")]
    public string? RevisionId { get; init; }

    [JsonPropertyName("changed")]
    public int Changed { get; init; }

    [JsonPropertyName("diffs")]
    public IReadOnlyList<PolicyPreviewDiffDto> Diffs { get; init; } = Array.Empty<PolicyPreviewDiffDto>();

    [JsonPropertyName("issues")]
    public IReadOnlyList<PolicyPreviewIssueDto> Issues { get; init; } = Array.Empty<PolicyPreviewIssueDto>();
}

public sealed record PolicyPreviewDiffDto
{
    [JsonPropertyName("findingId")]
    public string? FindingId { get; init; }

    [JsonPropertyName("baseline")]
    public PolicyPreviewVerdictDto? Baseline { get; init; }

    [JsonPropertyName("projected")]
    public PolicyPreviewVerdictDto? Projected { get; init; }

    [JsonPropertyName("changed")]
    public bool Changed { get; init; }
}

public sealed record PolicyPreviewIssueDto
{
    [JsonPropertyName("code")]
    public string Code { get; init; } = string.Empty;

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

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

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