using DiplomovaPrace.DataLayer.Repositories.Products;
using DiplomovaPrace.Model.Products;
using Havit.Data.Patterns.DataSeeds;
using Havit.Data.Patterns.DataSeeds.Profiles;
using Havit.Data.Patterns.Exceptions;
using Havit.Data.Patterns.UnitOfWorks;

namespace DiplomovaPrace.DataLayer.Seeds
{
	public class ProductCategorySeed : DataSeed<DefaultProfile>
	{
		private readonly IProductCategoryRepository productCategoryRepository;
		private readonly IUnitOfWork unitOfWork;

		public ProductCategorySeed(IProductCategoryRepository productCategoryRepository, IUnitOfWork unitOfWork)
		{
			this.productCategoryRepository = productCategoryRepository;
			this.unitOfWork = unitOfWork;
		}

		public override void SeedData()
		{
			ProductCategory root;
			try
			{
				root = productCategoryRepository.GetObject((int)ProductCategory.Entry.Root);
			}
			catch (ObjectNotFoundException)
			{
				root = new ProductCategory
				{
					Name = "Root"
				};

				unitOfWork.AddForInsert(root);
				unitOfWork.Commit();
			}
//#if DEBUG
			ProductCategory[] data = new ProductCategory[]
			{
				new ProductCategory
				{
					Name = "Drůbež",
					Description = "",
					ParentID = root.ID
				},
				new ProductCategory
				{
					Name = "Prasata",
					Description = "",
					ParentID = root.ID
				},
				new ProductCategory
				{
					Name = "Skot",
					Description = "",
					ParentID = root.ID
				},
				new ProductCategory
				{
					Name = "Koně/Ovce/Kozy",
					Description = "",
					ParentID = root.ID
				},
				new ProductCategory
				{
					Name = "Hlodavci/Králíci",
					Description = "",
					ParentID = root.ID
				},
				new ProductCategory
				{
					Name = "Psi",
					Description = "",
					ParentID = root.ID
				},
				new ProductCategory
				{
					Name = "Kočky",
					Description = "",
					ParentID = root.ID
				},
				//new ProductCategory
				//{
				//	Name = "Hlodavci",
				//	Description = "",
				//	ParentID = root.ID
				//},
				new ProductCategory
				{
					Name = "Ptactvo",
					Description = "",
					ParentID = root.ID
				},
				new ProductCategory
				{
					Name = "Ryby",
					Description = "",
					ParentID = root.ID
				},
				new ProductCategory
				{
					Name = "Zahrada",
					Description = "",
					ParentID = root.ID
				}
			};

			Seed(For(data).PairBy(i => i.Name).WithoutUpdate());
//#endif
		}
	}
}
