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

namespace StellaOps.Authority.Revocation;

internal sealed class RevocationBundleModel
{
    [JsonPropertyName("schemaVersion")]
    [JsonPropertyOrder(1)]
    public required string SchemaVersion { get; init; }

    [JsonPropertyName("issuer")]
    [JsonPropertyOrder(2)]
    public required string Issuer { get; init; }

    [JsonPropertyName("bundleId")]
    [JsonPropertyOrder(3)]
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    public string? BundleId { get; set; }

    [JsonPropertyName("issuedAt")]
    [JsonPropertyOrder(4)]
    public required DateTimeOffset IssuedAt { get; init; }

    [JsonPropertyName("validFrom")]
    [JsonPropertyOrder(5)]
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    public DateTimeOffset? ValidFrom { get; init; }

    [JsonPropertyName("expiresAt")]
    [JsonPropertyOrder(6)]
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    public DateTimeOffset? ExpiresAt { get; init; }

    [JsonPropertyName("sequence")]
    [JsonPropertyOrder(7)]
    public required long Sequence { get; init; }

    [JsonPropertyName("signingKeyId")]
    [JsonPropertyOrder(8)]
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    public string? SigningKeyId { get; set; }

    [JsonPropertyName("revocations")]
    [JsonPropertyOrder(9)]
    public required List<RevocationEntryModel> Revocations { get; init; }

    [JsonPropertyName("metadata")]
    [JsonPropertyOrder(10)]
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    public SortedDictionary<string, string?>? Metadata { get; init; }
}
