using Blazor_DotNet8_MovieApp.Data;
using Blazor_DotNet8_MovieApp.Models;
using Microsoft.EntityFrameworkCore;

namespace Blazor_DotNet8_MovieApp.Services
{
    public class MovieReviewService : IMovieReviewService
    {
        private readonly MovieReviewDbContext movieReviewDbContext;

        public MovieReviewService(MovieReviewDbContext movieReviewDbContext)
        {
            this.movieReviewDbContext = movieReviewDbContext;
        }

        public async Task<MovieModel?> GetMovieById(int id)
        {
            return await movieReviewDbContext.Movies.SingleOrDefaultAsync(m => m.Id == id);
        }

        public async Task<List<MovieModel>?> GetMovies()
        {
            return await movieReviewDbContext.Movies.ToListAsync<MovieModel>();
        }
    }
}
