using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;

namespace sotd.Pages;

public class IndexModel : PageModel
{
    private readonly ILogger<IndexModel> _logger;

    public IndexModel(ILogger<IndexModel> logger)
    {
        _logger = logger;
    }

    [BindProperty]
    public List<SongSuggestion> SongSuggestions { get; set; } = new List<SongSuggestion>();

    public Task OnGet()
    {
        using var dci = DataContext.Instance;
        SongSuggestions = dci.SongSuggestions.OrderByDescending(s => s.Date)
            .Take(50)
            .Include(s => s.Song)
            .Include(s => s.User)
            .ToList();
        return Task.CompletedTask;
    }
}
