using DAL.Models.Entities;
using DAL.Models.Filters;
using HRD.WebApi.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DAL.Repositories
{
    public class WindreamSearchRepository : BaseRepository<WindreamSearch>
    {
        public WindreamSearchRepository(WebApiContext context, ILogger<WindreamSearchRepository> logger) : base(context, logger)
        {
        }

        public async Task<List<WindreamSearch>> GetListByFilterAsync(ClientIdFilter filter, bool asNoTracking = true)
        {
            var items = this.RepositoryContext.Set<WindreamSearch>().AsQueryable();

            if (filter.ClientId != null)
            {
                items = items.Where(x => x.ClientId == filter.ClientId);
            }

            return asNoTracking ? await items.AsNoTracking().ToListAsync() : await items.ToListAsync();
        }
    }
}