using ShipyardContracts.BindingModels;
using ShipyardContracts.ViewModels;
using ShipyardDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace ShipyardListImplement.Models
{
    public class Ship:IShipModel
    {
        public int Id { get; private set; }

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

        public double Price { get; private set; }
        public Dictionary<int, (IDetailModel, int)> ShipDetails { get; private set; } = new Dictionary<int, (IDetailModel, int)>();
        public static Ship? Create(ShipBindingModel? model)
        {
            if (model == null)
            {
                return null;
            }
            return new Ship()
            {
                Id = model.Id,
                ShipName = model.ShipName,
                Price = model.Price,
                ShipDetails = model.ShipDetails
            };
        }
        public void Update(ShipBindingModel? model)
        {
            if (model == null)
            {
                return;
            }
            ShipName = model.ShipName;
            Price = model.Price;
            ShipDetails = model.ShipDetails;
        }
        public ShipViewModel GetViewModel => new()
        {
            Id = Id,
            ShipName = ShipName,
            Price = Price,
            ShipDetails = ShipDetails
        };

    }
}
