namespace DodoSSH.Api.Features.Teams;

/// <summary>
/// Source-generated log events for teams, membership and vault key grants.
/// </summary>
/// <remarks>
/// Ids, roles and outcomes only. Never a wrapped key, a signature or a fingerprint: the sharing graph
/// is already visible to the operator (docs/crypto.md §10) and there is nothing to gain by adding key
/// material to what a log aggregator keeps.
/// </remarks>
internal static partial class TeamLog
{
    [LoggerMessage(
        EventId = 2101,
        Level = LogLevel.Information,
        Message = "Created team {TeamId} for user {UserId}.")]
    internal static partial void TeamCreated(ILogger logger, Guid teamId, Guid userId);

    [LoggerMessage(
        EventId = 2102,
        Level = LogLevel.Information,
        Message = "Added user {MemberId} to team {TeamId} as {Role}, by {ActorId}.")]
    internal static partial void MemberAdded(
        ILogger logger, Guid teamId, Guid memberId, Domain.TeamRole role, Guid actorId);

    [LoggerMessage(
        EventId = 2103,
        Level = LogLevel.Information,
        Message = "Changed user {MemberId} in team {TeamId} to {Role}, by {ActorId}.")]
    internal static partial void MemberRoleChanged(
        ILogger logger, Guid teamId, Guid memberId, Domain.TeamRole role, Guid actorId);

    /// <remarks>
    /// Warning rather than information, and it names the grant count. Removal is the operation whose
    /// consequences are least like what the word implies — it blocks future reads and returns nothing
    /// already downloaded — so it is the one worth being able to find in a log afterwards.
    /// </remarks>
    [LoggerMessage(
        EventId = 2104,
        Level = LogLevel.Warning,
        Message = "Removed user {MemberId} from team {TeamId} by {ActorId}; revoked {GrantCount} vault "
            + "key grant(s). Vaults are flagged for rekey; already-downloaded data is unaffected.")]
    internal static partial void MemberRemoved(
        ILogger logger, Guid teamId, Guid memberId, Guid actorId, int grantCount);

    [LoggerMessage(
        EventId = 2105,
        Level = LogLevel.Information,
        Message = "Created team vault {VaultId} for team {TeamId}, by {ActorId}.")]
    internal static partial void TeamVaultCreated(
        ILogger logger, Guid vaultId, Guid teamId, Guid actorId);

    [LoggerMessage(
        EventId = 2106,
        Level = LogLevel.Information,
        Message = "Issued a key grant on vault {VaultId} generation {KeyGeneration} to {RecipientId}, "
            + "by {ActorId}.")]
    internal static partial void GrantIssued(
        ILogger logger, Guid vaultId, int keyGeneration, Guid recipientId, Guid actorId);

    [LoggerMessage(
        EventId = 2107,
        Level = LogLevel.Warning,
        Message = "Revoked the key grant on vault {VaultId} held by {RecipientId}, by {ActorId}. "
            + "Blocks future reads only; see ADR 0001.")]
    internal static partial void GrantRevoked(
        ILogger logger, Guid vaultId, Guid recipientId, Guid actorId);
}
