using FishFactoryContracts.BindingModels;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModels.Models;

namespace FishFactoryListImplement.Models
{
    public class Canned : ICannedModel
    {
        public int Id { get; private set; }
        public string CannedName { get; private set; } = string.Empty;
        public double Price { get; private set; }
        public Dictionary<int, (IIngredientModel, int)> CannedIngredients
        {
            get;
            private set;
        } = new Dictionary<int, (IIngredientModel, int)>();

        public static Canned? Create(CannedBindingModel? model)
        {
            if (model == null)
            {
                return null;
            }
            return new Canned()
            {
                Id = model.Id,
                CannedName = model.CannedName,
                Price = model.Price,
                CannedIngredients = model.CannedIngredients
            };
        }

        public void Update(CannedBindingModel? model)
        {
            if (model == null)
            {
                return;
            }
            CannedName = model.CannedName;
            Price = model.Price;
            CannedIngredients = model.CannedIngredients;
        }

        public CannedViewModel GetViewModel => new()
        {
            Id = Id,
            CannedName = CannedName,
            Price = Price,
            CannedIngredients = CannedIngredients
        };
    }
}
