using UnityEngine;
using UnityEngine.Timeline;

public sealed class SpaceStantionView : MonoBehaviour, IInteractableObjectView
{
    [SerializeField]
    private string id = string.Empty;
    [SerializeField]
    private float markerRadius = 1;

    public string Id => id;

    public float Radius => markerRadius;
    public SpaceStantion Stantion{ get; private set; }

    public IInteractableObject GetInteractableObject() => Stantion;

    public void Init(SpaceStantion stantion) {
        Stantion = stantion;
        transform.localPosition = stantion.Position;
        transform.localRotation = stantion.Rotation;
        name = $"{stantion.TypeId}_{stantion.Name}";
    }

    [ContextMenu("find radius")]
    private void FindMinRadius()
    {
        var renderers = GetComponentsInChildren<MeshRenderer>();
        var radius = 1f;
        foreach (var renderer in renderers) {
            radius = Mathf.Max(radius, renderer.bounds.size.x, renderer.bounds.size.y, renderer.bounds.size.z);
        }
        markerRadius = radius;
    }

    private void OnDrawGizmosSelected()
    {
        Gizmos.DrawWireSphere(transform.position, markerRadius);
    }
}
