Files
VORTEX-REC-LEAK/Models/ActionLink.cs
T
2026-07-23 18:21:43 -07:00

69 lines
2.1 KiB
C#

using LiteDB;
using static DeluxeBackend.Enums;
namespace DeluxeBackend.Models
{
public class ActionLinkExtraData
{
public ulong? DiscordUserId { get; set; } = null;
public long? RoomId { get; set; } = null;
}
public class ActionLink
{
[BsonId]
public long Id { get; set; }
public PlatformType? Platform { get; set; } = null;
public required string Code { get; set; }
public required long CreatorPlayerId { get; set; }
public required string Description { get; set; }
public required ActionLinkType Type { get; set; }
public ActionLinkExtraData? ExtraData { get; set; } = null;
public required DateTime ExpiresAt { get; set; }
public int MaxUses { get; set; } = 100;
public int Uses { get; set; } = 0;
[BsonIgnore]
public bool IsValid
{
get
{
var now = DateTime.UtcNow;
bool timeValid = ExpiresAt.Kind == DateTimeKind.Utc
? ExpiresAt > now
: ExpiresAt.ToUniversalTime() > now;
return timeValid && Uses < MaxUses;
}
}
[BsonIgnore]
public Dictionary<string, object> ToDictionary()
{
Dictionary<string, object> dataMeow = new()
{
["Type"] = (int)Type
};
if (Type == ActionLinkType.DiscordLink)
{
dataMeow["Type"] = (int)ActionLinkType.Room;
ExtraData!.RoomId = 2;
}
if (Platform != null)
{
dataMeow["Platform"] = (int)Platform;
}
if (ExtraData != null)
{
dataMeow["ExtraJson"] = System.Text.Json.JsonSerializer.Serialize(ExtraData);
}
Dictionary<string, object> data = new()
{
["creatorPlayerId"] = CreatorPlayerId,
["data"] = System.Text.Json.JsonSerializer.Serialize(dataMeow),
["isValid"] = IsValid
};
return data;
}
}
}