using System;
using System.Linq.Expressions;

using DataAccess.Domain.Entities;
using DataAccess.Repository.Abstract;

namespace DataAccess.Repository.Query {
	public class CategoryByParentIdQuery : QueryBase<Category> {
		private int? parentCategoryId;

		public CategoryByParentIdQuery(int? parentCategoryId) {
			this.parentCategoryId = parentCategoryId;
		}

		public override Expression<Func<Category, bool>> MatchingCriteria {
			get {
				if (this.parentCategoryId.HasValue) {
					// sub categories
					return category => category.ParentCategory.Id == parentCategoryId.Value;
				} else {
					// root level category
					return category => category.ParentCategory == null || category.ParentCategory.Id == null;
				}
			}
		}
	}
}
