using SoftwareInstallationContracts.BindingModels;
using SoftwareInstallationContracts.ViewModels;
using SoftwareInstallationDataModels;
using SoftwareInstallationDataModels.Models;

namespace SoftwareInstallationListImplement
{
    public class Shop : IShopModel
    {
        public string Name { get; private set; } = string.Empty;

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

        public int MaxCountPackages { get; private set; }

        public DateTime DateOpening { get; private set; }

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

        public int Id { get; private set; }

        public static Shop? Create(ShopBindingModel? model)
        {
            if (model == null)
            {
                return null;
            }
            return new Shop()
            {
                Id = model.Id,
                Name = model.Name,
                Address = model.Address,
                DateOpening = model.DateOpening,
                MaxCountPackages = model.MaxCountPackages,
                Packages = new()
            };
        }
        public void Update(ShopBindingModel? model)
        {
            if (model == null)
            {
                return;
            }
            Name = model.Name;
            Address = model.Address;
            DateOpening = model.DateOpening;
            MaxCountPackages = model.MaxCountPackages;
            Packages = model.Packages;
        }
        public ShopViewModel GetViewModel => new()
        {
            Id = Id,
            Name = Name,
            Address = Address,
            Packages = Packages,
            DateOpening = DateOpening,
            MaxCountPackages = MaxCountPackages,
        };
    }
}
