using NeonSprawl.Server.Game.Factions;
namespace NeonSprawl.Server.Game.Rewards;
/// Id normalization and composite keys for reward delivery stores (NEO-126).
public static class RewardDeliveryIds
{
/// Trim + lowercase; empty when input is null/whitespace.
public static string NormalizePlayerId(string? playerId)
{
var trimmed = playerId?.Trim();
if (string.IsNullOrEmpty(trimmed))
{
return string.Empty;
}
return trimmed.ToLowerInvariant();
}
/// Trim + lowercase; empty when input is null/whitespace.
public static string NormalizeQuestId(string? questId) => NormalizePlayerId(questId);
/// Stable idempotency key for quest completion delivery.
public static string MakeIdempotencyKey(string? playerId, string? questId)
{
var p = NormalizePlayerId(playerId);
var q = NormalizeQuestId(questId);
if (p.Length == 0 || q.Length == 0)
{
return string.Empty;
}
return $"{p}:quest_complete:{q}";
}
/// Stable audit row id for one rep grant on a quest completion delivery (NEO-138).
public static string MakeReputationDeltaId(string idempotencyKey, string? factionId)
{
var faction = FactionStandingIds.NormalizeFactionId(factionId);
if (idempotencyKey.Length == 0 || faction.Length == 0)
{
return string.Empty;
}
return $"{idempotencyKey}:rep:{faction}";
}
/// Rollback audit row id for compensating rep revert (NEO-138).
public static string MakeReputationRollbackDeltaId(string reputationDeltaId) =>
reputationDeltaId.Length == 0 ? string.Empty : $"{reputationDeltaId}:rollback";
/// Composite store key for + .
public static string MakeStoreKey(string? playerId, string? questId)
{
var p = NormalizePlayerId(playerId);
var q = NormalizeQuestId(questId);
if (p.Length == 0 || q.Length == 0)
{
return string.Empty;
}
return $"{p}\0{q}";
}
}