using System;
using System.Collections.Generic;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace StellaOps.Authority.Storage.Mongo.Documents;

/// <summary>
/// Represents a revocation entry emitted by Authority (subject/client/token/key).
/// </summary>
[BsonIgnoreExtraElements]
public sealed class AuthorityRevocationDocument
{
    [BsonId]
    [BsonRepresentation(BsonType.ObjectId)]
    public string Id { get; set; } = ObjectId.GenerateNewId().ToString();

    [BsonElement("category")]
    public string Category { get; set; } = string.Empty;

    [BsonElement("revocationId")]
    public string RevocationId { get; set; } = string.Empty;

    [BsonElement("tokenType")]
    [BsonIgnoreIfNull]
    public string? TokenType { get; set; }

    [BsonElement("subjectId")]
    [BsonIgnoreIfNull]
    public string? SubjectId { get; set; }

    [BsonElement("clientId")]
    [BsonIgnoreIfNull]
    public string? ClientId { get; set; }

    [BsonElement("reason")]
    [BsonIgnoreIfNull]
    public string? Reason { get; set; }

    [BsonElement("reasonDescription")]
    [BsonIgnoreIfNull]
    public string? ReasonDescription { get; set; }

    [BsonElement("revokedAt")]
    public DateTimeOffset RevokedAt { get; set; }

    [BsonElement("effectiveAt")]
    [BsonIgnoreIfNull]
    public DateTimeOffset? EffectiveAt { get; set; }

    [BsonElement("expiresAt")]
    [BsonIgnoreIfNull]
    public DateTimeOffset? ExpiresAt { get; set; }

    [BsonElement("scopes")]
    [BsonIgnoreIfNull]
    public List<string>? Scopes { get; set; }

    [BsonElement("fingerprint")]
    [BsonIgnoreIfNull]
    public string? Fingerprint { get; set; }

    [BsonElement("metadata")]
    [BsonIgnoreIfNull]
    public Dictionary<string, string?>? Metadata { get; set; }

    [BsonElement("createdAt")]
    public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;

    [BsonElement("updatedAt")]
    public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.UtcNow;
}
