using BarContracts.BindingModels;
using BarContracts.ViewModels;
using BarDataModels.Models;

namespace BarListImplement.Models
{
    public class Component : IComponentModel
    {
        public int Id { get; private set; }

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

        public double Cost { get; set; }

        public static Component? Create(ComponentBindingModel? Model)
        {
            if (Model is null)
                return null;

            return new Component()
            {
                Id = Model.Id,
                ComponentName = Model.ComponentName,
                Cost = Model.Cost
            };
        }

        public void Update(ComponentBindingModel? Model)
        {
            if (Model is null)
                return;

            ComponentName = Model.ComponentName;
            Cost = Model.Cost;
        }

        public ComponentViewModel GetViewModel => new()
        {
            Id = Id,
            ComponentName = ComponentName,
            Cost = Cost
        };
    }
}
