using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace StellaOps.Authority.Storage.Mongo.Documents;

/// <summary>
/// Represents an OAuth client/application registered with Authority.
/// </summary>
[BsonIgnoreExtraElements]
public sealed class AuthorityClientDocument
{
    [BsonId]
    [BsonRepresentation(BsonType.ObjectId)]
    public string Id { get; set; } = ObjectId.GenerateNewId().ToString();

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

    [BsonElement("clientType")]
    public string ClientType { get; set; } = "confidential";

    [BsonElement("displayName")]
    [BsonIgnoreIfNull]
    public string? DisplayName { get; set; }

    [BsonElement("description")]
    [BsonIgnoreIfNull]
    public string? Description { get; set; }

    [BsonElement("secretHash")]
    [BsonIgnoreIfNull]
    public string? SecretHash { get; set; }

    [BsonElement("permissions")]
    public List<string> Permissions { get; set; } = new();

    [BsonElement("requirements")]
    public List<string> Requirements { get; set; } = new();

    [BsonElement("redirectUris")]
    public List<string> RedirectUris { get; set; } = new();

    [BsonElement("postLogoutRedirectUris")]
    public List<string> PostLogoutRedirectUris { get; set; } = new();

    [BsonElement("properties")]
    public Dictionary<string, string?> Properties { get; set; } = new(StringComparer.OrdinalIgnoreCase);

    [BsonElement("plugin")]
    [BsonIgnoreIfNull]
    public string? Plugin { get; set; }

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

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

    [BsonElement("disabled")]
    public bool Disabled { get; set; }
}
