103 lines
3.9 KiB
C#
103 lines
3.9 KiB
C#
using LiteDB;
|
|
using static DeluxeBackend.Enums;
|
|
|
|
namespace DeluxeBackend.Models
|
|
{
|
|
public class Invention
|
|
{
|
|
[BsonId]
|
|
public long Id { get; set; }
|
|
public required Guid ReplicationId { get; set; }
|
|
[BsonRef("accounts")]
|
|
public required Account Creator { get; set; }
|
|
public required string Name { get; set; }
|
|
public required string Description { get; set; }
|
|
public required string ImageName { get; set; }
|
|
public List<InventionVersion> Versions { get; set; } = [];
|
|
public required int CurrentVersionNumber { get; set; }
|
|
public required RoomAccessibility Accessibility { get; set; }
|
|
public DateTime ModifiedAt { get; set; } = DateTime.UtcNow;
|
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
|
public DateTime? FirstPublishedAt { get; set; }
|
|
[BsonRef("rooms")]
|
|
public required Room Room { get; set; }
|
|
public List<long> DownloadIds { get; set; } = [];
|
|
public List<long> CheeredIds { get; set; } = [];
|
|
|
|
public InventionPermission CreatorPermission { get; set; } = InventionPermission.Unassigned;
|
|
public InventionPermission GeneralPermission { get; set; } = InventionPermission.Unassigned;
|
|
public bool AllowTrial { get; set; } = false;
|
|
public int? Price { get; set; }
|
|
|
|
[BsonIgnore]
|
|
public Dictionary<string, object?> ToDictionary()
|
|
{
|
|
#pragma warning disable CS8601 // Possible null reference assignment.
|
|
Dictionary<string, object?> data = new()
|
|
{
|
|
["InventionId"] = Id,
|
|
["ReplicationId"] = ReplicationId.ToString(),
|
|
["CreatorPlayerId"] = Creator.Id,
|
|
["Name"] = Name,
|
|
["Description"] = Description,
|
|
["ImageName"] = ImageName,
|
|
["CurrentVersionNumber"] = CurrentVersionNumber,
|
|
["Accessibility"] = Accessibility,
|
|
["ModifiedAt"] = ModifiedAt.ToString("O"),
|
|
["CreatedAt"] = CreatedAt.ToString("O"),
|
|
["CreationRoomId"] = Room.Id,
|
|
["NumPlayersHaveUsedInRoom"] = -1,
|
|
["NumDownloads"] = DownloadIds.Count,
|
|
["CheerCount"] = CheeredIds.Count,
|
|
["CreatorPermission"] = CreatorPermission,
|
|
["GeneralPermission"] = GeneralPermission,
|
|
["IsAGInvention"] = false,
|
|
["IsCertifiedInvention"] = false,
|
|
["AllowTrial"] = AllowTrial
|
|
|
|
};
|
|
if (FirstPublishedAt.HasValue)
|
|
{
|
|
data["FirstPublishedAt"] = FirstPublishedAt.Value.ToString("O");
|
|
}
|
|
if (Price.HasValue)
|
|
{
|
|
data["Price"] = Price.Value;
|
|
}
|
|
return data;
|
|
#pragma warning restore CS8601
|
|
}
|
|
}
|
|
|
|
public class InventionVersion
|
|
{
|
|
public required int Id { get; set; }
|
|
public required Guid ReplicationId { get; set; }
|
|
public required int InstantiationCost { get; set; }
|
|
public required int LightsCost { get; set; }
|
|
public required int ChipsCost { get; set; }
|
|
public required int CloudVariablesCost { get; set; }
|
|
public required string BlobName { get; set; }
|
|
|
|
[BsonIgnore]
|
|
public Dictionary<string, object?> ToDictionary(long inventionId)
|
|
{
|
|
|
|
#pragma warning disable CS8601 // Possible null reference assignment.
|
|
Dictionary<string, object?> data = new()
|
|
{
|
|
["InventionId"] = inventionId,
|
|
["ReplicationId"] = ReplicationId.ToString(),
|
|
["VersionNumber"] = Id,
|
|
["InstantiationCost"] = InstantiationCost,
|
|
["LightsCost"] = LightsCost,
|
|
["ChipsCost"] = ChipsCost,
|
|
["CloudVariablesCost"] = CloudVariablesCost,
|
|
["BlobName"] = BlobName
|
|
};
|
|
return data;
|
|
#pragma warning restore CS8601
|
|
}
|
|
}
|
|
}
|