using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; namespace Content.Server.Database; // // Contains model definitions primarily related to custom vote logging. // internal static class ModelCustomVoteLog { public static void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity() .HasOne(cvl => cvl.Initiator) .WithMany() .HasForeignKey(cvl => cvl.InitiatorId) .HasPrincipalKey(p => p.UserId) .OnDelete(DeleteBehavior.SetNull) .IsRequired(false); modelBuilder.Entity() .HasKey(cvl => new { cvl.VoteId, cvl.OptionIdx }); } } /// /// A single admin-initiated custom vote logged in the database. /// public sealed class CustomVoteLog { public int Id { get; set; } /// /// The round ID the vote was made in. /// public int RoundId { get; set; } /// /// The time the vote was created at. /// public DateTime TimeCreated { get; set; } /// /// The player-facing title for the vote. /// public required string Title { get; set; } /// /// The user ID of the admin that created the vote. /// public Guid? InitiatorId { get; set; } /// /// State of the vote. /// public CustomVoteState State { get; set; } /// /// The playing-facing options the vote has. /// public List? Options { get; set; } /// /// The round the vote was made in. /// public Round? Round { get; set; } /// /// The admin that created the vote. /// public Player? Initiator { get; set; } } /// /// An option for a logged . /// public sealed class CustomVoteLogOption { /// /// The vote ID this option is part of. /// public int VoteId { get; set; } /// /// The index of the option in the option list. /// public short OptionIdx { get; set; } /// /// The player-facing text for this option. /// public required string Text { get; set; } /// /// How many players voted for this option. /// /// /// This field is only populated for votes with state . /// public int VoteCount { get; set; } /// /// The vote this option is part of. /// public CustomVoteLog? Vote { get; set; } } /// /// Possible states for entries. /// public enum CustomVoteState : byte { /// /// The vote is still active (likely was just made). /// Active, /// /// The vote finished and vote counts were written to database. /// Finished, /// /// The vote was canceled, no vote counts have been written to database. /// Cancelled, }