using GmRelay.Shared.Domain;

namespace GmRelay.Web.Services;

public sealed record PlayerAttendanceStats(
    Guid PlayerId,
    string DisplayName,
    string? TelegramUsername,
    long TotalSessions,
    long ConfirmedCount,
    long DeclinedCount,
    long NoResponseCount,
    long WaitlistedCount,
    long CancellationAffectedCount,
    decimal AttendanceRate
);

public sealed record SessionAuditLogEntry(
    Guid Id,
    Guid SessionId,
    long ActorTelegramId,
    string ActorName,
    string ChangeType,
    string? OldValue,
    string? NewValue,
    DateTime ChangedAt
);

public interface ISessionStore
{
    Task<List<WebGameGroup>> GetGroupsForGmAsync(long gmId);
    Task<WebGameGroup?> GetGroupAsync(Guid groupId);
    Task<bool> IsGroupManagerAsync(Guid groupId, long telegramId);
    Task<bool> IsGroupOwnerAsync(Guid groupId, long telegramId);
    Task<List<WebGroupManager>> GetGroupManagersAsync(Guid groupId);
    Task<List<WebSession>> GetUpcomingSessionsAsync(Guid groupId);
    Task<WebSession?> GetSessionAsync(Guid sessionId);
    Task<WebSessionBatch?> GetBatchAsync(Guid batchId);
    Task UpdateSessionAsync(Guid sessionId, Guid groupId, string title, DateTime scheduledAt, string joinLink, int? maxPlayers);
    Task PromoteWaitlistedPlayerAsync(Guid sessionId, Guid groupId);
    Task UpdateBatchDetailsAsync(Guid batchId, Guid groupId, string title, string joinLink);
    Task UpdateBatchNotificationModeAsync(Guid batchId, Guid groupId, SessionNotificationMode notificationMode);
    Task RescheduleBatchAsync(Guid batchId, Guid groupId, DateTime firstScheduledAt, int intervalDays);
    Task<WebSessionBatch> CloneBatchAsync(Guid batchId, Guid groupId, BatchCloneInterval interval);
    Task<List<WebCampaignTemplate>> GetCampaignTemplatesAsync(Guid groupId);
    Task<WebCampaignTemplate?> GetCampaignTemplateAsync(Guid templateId);
    Task<WebCampaignTemplate> CreateCampaignTemplateAsync(Guid groupId, CreateCampaignTemplateRequest request);
    Task DeleteCampaignTemplateAsync(Guid templateId, Guid groupId);
    Task<WebSessionBatch> CreateBatchFromTemplateAsync(Guid templateId, Guid groupId, DateTime firstScheduledAt);
    Task AddGroupCoGmAsync(Guid groupId, long ownerTelegramId, long coGmTelegramId, string displayName, string? telegramUsername);
    Task RemoveGroupCoGmAsync(Guid groupId, long coGmTelegramId);
    Task<List<WebParticipant>> GetSessionParticipantsAsync(Guid sessionId);
    Task RemovePlayerFromSessionAsync(Guid sessionId, Guid groupId, Guid participantId);
    Task<List<PlayerAttendanceStats>> GetGroupAttendanceStatsAsync(Guid groupId);
    Task LogSessionChangeAsync(Guid sessionId, long actorTelegramId, string actorName, string changeType, string? oldValue, string? newValue);
    Task<List<SessionAuditLogEntry>> GetSessionHistoryAsync(Guid sessionId);
}
