using System.Linq;
using UnityEngine;

[CreateAssetMenu(fileName = "ship views provider", menuName = "Ship Views Provider")]
public sealed class ShipViewProvider : ScriptableObject
{
    [SerializeField]
    private ShipView[] ships = null; // Set from editor
    [SerializeField]
    private ShipView defaultView = null; // Set from editor

    public ShipView CreateShipView(string id, Transform parent = null)
    {
        return Instantiate(GetPrefabById(id), parent);
    }

    private ShipView GetPrefabById(string id)
    {
        return ships.FirstOrDefault(ship => ship.Id == id) ?? defaultView;
    }
}
