using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.ViewModels;
using ConfectioneryDataModels.Models;

namespace ConfectioneryListImplement.Models
{
    public class Pastry : IPastryModel
    {
        public int Id { get; private set; }
        public string PastryName { get; private set; } = string.Empty;
        public double Price { get; private set; }
        public Dictionary<int, (IComponentModel, int)> PastryComponents
        {
            get;
            private set;
        } = new Dictionary<int, (IComponentModel, int)>();
        public static Pastry? Create(PastryBindingModel? model)
        {
            if (model == null)
            {
                return null;
            }
            return new Pastry()
            {
                Id = model.Id,
                PastryName = model.PastryName,
                Price = model.Price,
                PastryComponents = model.PastryComponents
            };
        }
        public void Update(PastryBindingModel? model)
        {
            if (model == null)
            {
                return;
            }
            PastryName = model.PastryName;
            Price = model.Price;
            PastryComponents = model.PastryComponents;
        }
        public PastryViewModel GetViewModel => new()
        {
            Id = Id,
            PastryName = PastryName,
            Price = Price,
            PastryComponents = PastryComponents
        };
    }
}