using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.ViewModels;
using IceCreamShopDataModels.Models;

namespace IceCreamShopListImplement.Models
{
    public class Shop : IShopModel
    {
        public int Id { get; private set; }

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

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

        public DateTime DateOpening { get; private set; }

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

        public int IceCreamsMaximum { get; private set; }

        public static Shop? Create(ShopBindingModel? model)
        {
            if (model == null)
            {
                return null;
            }
            return new Shop()
            {
                Id = model.Id,
                ShopName = model.ShopName,
                Address = model.Address,
                DateOpening = model.DateOpening,
                ShopIceCreams = model.ShopIceCreams, 
                IceCreamsMaximum = model.IceCreamsMaximum
            };
        }

        public void Update(ShopBindingModel? model)
        {
            if (model == null)
            {
                return;
            }
            ShopName = model.ShopName;
            Address = model.Address;
            DateOpening = model.DateOpening;
            ShopIceCreams = model.ShopIceCreams;
            IceCreamsMaximum = model.IceCreamsMaximum;
        }

        public ShopViewModel GetViewModel => new()
        {
            Id = Id,
            ShopName = ShopName,
            Address = Address,
            DateOpening = DateOpening,
            ShopIceCreams = ShopIceCreams,
            IceCreamsMaximum = IceCreamsMaximum
        };
    }
}
