using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.ViewModels;
using PlumbingRepairDataModels.Models;

namespace PlumbingRepairListImplement.Models
{
    public class Work : IWorkModel
    {
        public int Id { get; private set; }
        public string WorkName { get; private set; } = string.Empty;
        public double Price { get; private set; }
        public Dictionary<int, (IComponentModel, int)> WorkComponents { get; private set; } = new Dictionary<int, (IComponentModel, int)>();

        public static Work? Create(WorkBindingModel? model)
        {
            if (model == null)
            {
                return null;
            }
            return new Work()
            {
                Id = model.Id,
                WorkName = model.WorkName,
                Price = model.Price,
                WorkComponents = model.WorkComponents
            };
        }

        public void Update(WorkBindingModel? model)
        {
            if (model == null)
            {
                return;
            }
            WorkName = model.WorkName;
            Price = model.Price;
            WorkComponents = model.WorkComponents;
        }

        public WorkViewModel GetViewModel => new()
        {
            Id = Id,
            WorkName = WorkName,
            Price = Price,
            WorkComponents = WorkComponents
        };
    }
}
