using DinerContracts.BindingModels;
using DinerContracts.ViewModels;
using DinerDataModels.Models;

namespace DinerListImplement.Models
{
    public class Snack : ISnackModel
    {
        public int Id { get; private set; }
        public string SnackName { get; private set; } = string.Empty;
        public double Price { get; private set; }
        public Dictionary<int, (IComponentModel, int)> SnackComponents
        {
            get;
            private set;
        } = new Dictionary<int, (IComponentModel, int)>();
        public static Snack? Create(SnackBindingModel? model)
        {
            if (model == null)
            {
                return null;
            }
            return new Snack()
            {
                Id = model.Id,
                SnackName = model.SnackName,
                Price = model.Price,
                SnackComponents = model.SnackComponents
            };
        }
        public void Update(SnackBindingModel? model)
        {
            if (model == null)
            {
                return;
            }
            SnackName = model.SnackName;
            Price = model.Price;
            SnackComponents = model.SnackComponents;
        }
        public SnackViewModel GetViewModel => new()
        {
            Id = Id,
            SnackName = SnackName,
            Price = Price,
            SnackComponents = SnackComponents
        };
    }
}
