using BarContracts.BindingModels;
using BarContracts.ViewModels;
using BarDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

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

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

        [Required]
        public double Cost { get; set; }

        [ForeignKey("ComponentId")]
        public virtual List<CocktailComponent> CocktailComponents { get; set; } = new();

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

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

        public static Component Create(ComponentViewModel Model)
        {
            return new Component
            {
                Id = Model.Id,
                ComponentName = Model.ComponentName,
                Cost = Model.Cost
            };
        }

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

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

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