public async Task <PlaybackSession> GetById(string id, PlaybackSessionQueryOptions queryOptions = null)
        {
            var session = await _db.PlaybackSessions.Include(e => e.JoinedUsers).FirstOrDefaultAsync(e => e.Id == id);

            await PopulatePropertiesAsync(session, queryOptions);

            return(session);
        }
        public async Task <PlaybackSession> GetByDiscordIdAsync(string discordId, PlaybackSessionQueryOptions queryOptions = null)
        {
            var session = await _db.PlaybackSessions.Include(e => e.JoinedUsers)
                          .FirstOrDefaultAsync(m => m.DiscordVoiceChannelId == discordId);

            await PopulatePropertiesAsync(session, queryOptions);

            return(session);
        }
        private async Task PopulatePropertiesAsync(PlaybackSession session, PlaybackSessionQueryOptions queryOptions = null)
        {
            // Looks like this related property is being eager loaded. The inner if was never hit in testing
            if (session != null &&
                !string.IsNullOrWhiteSpace(session.CurrentSongPlaybackId) &&
                queryOptions != null)
            {
                var currentPlaybackId = session.CurrentSongPlaybackId;
                var playback          = await _db.SongPlaybackTrackers.FirstOrDefaultAsync(m => m.Id == currentPlaybackId);

                session.CurrentSongPlayback = playback ?? throw new Exception("Current playback cannot be null");
            }
        }
        public async Task <IList <PlaybackSession> > Get(int offset, int take, PlaybackSessionQueryOptions queryOptions = null)
        {
            IQueryable <PlaybackSession> query = _db.PlaybackSessions.AsQueryable();

            if (queryOptions != null)
            {
                if (queryOptions.IncludeJoinedUsers)
                {
                    query = query.Include(e => e.JoinedUsers);
                }
                if (queryOptions.IncludeCurrentPlayback)
                {
                    query = query.Include(e => e.CurrentSongPlayback);
                }
                if (queryOptions.IncludeCurrentPlayback && queryOptions.IncludeDiscordUsers)
                {
                    query = query.Include("JoinedUsers.DiscordUser");
                }
            }


            return(await query.Skip(offset).Take(take).ToListAsync());
        }