using BarContracts.BindingModels;
using BarContracts.ViewModels;
using BarDataModels.Models;

namespace BarListImplement.Models
{
    public class Cocktail : ICocktailModel
    {
        public int Id { get; private set; }

        public string CocktailName { get; private set; } = string.Empty;

        public double Price { get; private set; }

        public Dictionary<int, (IComponentModel, int)> CocktailComponents
        {
            get;
            private set;
        } = new Dictionary<int, (IComponentModel, int)>();

        public static Cocktail? Create(CocktailBindingModel? Model)
        {
            if (Model is null)
                return null;

            return new Cocktail()
            {
                Id = Model.Id,
                CocktailName = Model.CocktailName,
                Price = Model.Price,
                CocktailComponents = Model.CocktailComponents
            };
        }

        public void Update(CocktailBindingModel? Model)
        {
            if (Model is null)
                return;

            CocktailName = Model.CocktailName;
            Price = Model.Price;
            CocktailComponents = Model.CocktailComponents;
        }

        public CocktailViewModel GetViewModel => new()
        {
            Id = Id,
            CocktailName = CocktailName,
            Price = Price,
            CocktailComponents = CocktailComponents
        };
    }
}
