using collAnon.Pub.Shared;
using drinkMe.Server.Models;
using drinkMe.Server.Services.Interfaces;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace drinkMe.Server.Services
{
	public class DataService : IDataService
	{
		List<DiscountCode> DiscountCodes = new List<DiscountCode>
		{
			new DiscountCode{ Code ="ITS_M0NDAY", DiscountPercentage = 15, ApplicableProducts = new[] { 2 } },
			new DiscountCode{ Code ="ITS_K1NDA_COLD", DiscountPercentage = 30, ApplicableProducts = new[] { 4 } },
			new DiscountCode{ Code ="I_NEED_R3LAX", DiscountPercentage = 25, ApplicableProducts = new[] { 3 } },
			new DiscountCode{ Code ="D1AMOND_HANDS", DiscountPercentage = 100, ApplicableProducts = new[] { 1 } }
		};

		public List<Drink> GetDrinks() =>
			new List<Drink>
			{
				new Drink
				{
						Id = 1,
						Name = "Italian Coffee",
						Description = "Short but strong.",
						Price = 3.50f,
						PictureName = "italian-coffee.jpg"
				},
				new Drink
				{
						Id = 2,
						Name = "American Coffee",
						Description = "Dilluted in water to a cup size, not as strong as the italian one.",
						Price = 3.0f,
						PictureName = "american-coffee.jpg"
				},
				new Drink
				{
						Id = 3,
						Name = "Tea",
						Description = "Black Earl Grey, good alternative to coffee from time to time.",
						Price = 2.0f,
						PictureName = "tea.png"
				},
				new Drink
				{
						Id = 4,
						Name = "Chocolate",
						Description = "Your dose of sugar and calories, just don't loose the hang.",
						Price = 4.0f,
						PictureName = "chocolate.jpg"
				}
			};

		public async Task<WebResult> IsValidDiscountCode(string code)
		{
			var result = new WebResult();
			if (!DiscountCodes.Any(dc => dc.Code == code))
				return result.Invalidate("Invalid discount code.", StatusCodes.Status404NotFound);

			result.Data = DiscountCodes.First(dc => dc.Code == code);
			return result;
		}
	}
}
