﻿using System.Collections.Generic;
using System.Linq;
using GenderPayGap.Extensions;
using GenderPayGap.Core.Models;

namespace GenderPayGap.WebUI.Classes
{

    public class SearchFilterBuilder
    {
        IQueryable<ViewDataModel> expression;

        public SearchFilterBuilder(IQueryable<ViewDataModel> data)
        {
            this.expression = data;
        }

        public void ByName(string name)
        {
            expression = expression.Where(x => x.OrganisationName.ContainsI(name));
        }

        public void BySize(IEnumerable<int> filterBySizeIds)
        {
            expression = expression.Where(x => filterBySizeIds.Any(fx => fx == x.OrganisationSize));
        }

        public void BySector(IEnumerable<string> filterBySicSectionIds)
        {
            expression = expression.Where(x => filterBySicSectionIds.Any(fs => x.SicSectionIds.Contains(fs)));
        }

        public IList<ViewDataModel> ToList()
        {
            return expression.OrderBy(x => x.OrganisationName).ToList();
        }

    }

}