using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RenovationWorkContracts.BindingModels;
using RenovationWorkContracts.ViewModels;
using RenovationWorkDataModels.Models;

namespace RenovationWorkListImplement.Models
{
    public class Repair : IRepairModel
    {
        public int Id { get; private set; }
        public string RepairName { get; private set; } = string.Empty;
        public double Price { get; private set; }
        public Dictionary<int, (IComponentModel, int)> RepairComponents
        {
            get;
            private set;
        } = new Dictionary<int, (IComponentModel, int)>();
        public static Repair? Create(RepairBindingModel? model)
        {
            if (model == null)
            {
                return null;
            }
            return new Repair()
            {
                Id = model.Id,
                RepairName = model.RepairName,
                Price = model.Price,
                RepairComponents = model.RepairComponents
            };
        }
        public void Update(RepairBindingModel? model)
        {
            if (model == null)
            {
                return;
            }
            RepairName = model.RepairName;
            Price = model.Price;
            RepairComponents = model.RepairComponents;
        }
        public RepairViewModel GetViewModel => new()
        {
            Id = Id,
            RepairName = RepairName,
            Price = Price,
            RepairComponents = RepairComponents
        };
    }
}
