using RankingApp.Data.Models;

namespace RankingApp.Data.Services
{
    public class RankingService
    {
         private ApplicationDbContext _context;

        public RankingService(ApplicationDbContext context)
        {
            _context = context;
        }

        // Create
        public Task<GameResult> AddGameResult(GameResult gameResult)
        {
            _context.GameResults.Add(gameResult);
            _context.SaveChanges();

            return Task.FromResult(gameResult);
        }

        // Read
        public Task<List<GameResult>> GetGameResultsAsync()
        {
            List<GameResult> results = _context.GameResults
                .OrderByDescending(item => item.Score) 
                .ToList();

            return Task.FromResult(results);
        }

        // Update

        // Delete
    }
}
