using GarmentFactoryContracts.BindingModels;
using GarmentFactoryContracts.ViewModels;
using GarmentFactoryDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GarmentFactoryListImplement.Models
{
    public class Textile : ITextileModel
    {
        public int Id { get; private set; }
        public string TextileName { get; private set; } = string.Empty;
        public double Price { get; private set; }
        public Dictionary<int, (IComponentModel, int)> TextileComponents
        {
            get;
            private set;
        } = new Dictionary<int, (IComponentModel, int)>();
        public static Textile? Create(TextileBindingModel? model)
        {
            if (model == null)
            {
                return null;
            }
            return new Textile()
            {
                Id = model.Id,TextileName = model.TextileName, Price = model.Price, TextileComponents = model.TextileComponents
            };
        }
        public void Update(TextileBindingModel? model)
        {
            if (model == null)
            {
                return;
            }
            TextileName = model.TextileName;
            Price = model.Price;
            TextileComponents = model.TextileComponents;
        }
        public TextileViewModel GetViewModel => new()
        {
            Id = Id,
            TextileName = TextileName,
            Price = Price,
            TextileComponents = TextileComponents
        };
    }
}
