using System.Collections.Generic;
using Unity.Cinemachine;
using UnityEngine;

public abstract class CameraRigBase : CinemachineCameraManagerBase, IInputAxisOwner
{
    protected PlayerCharacterController _controller;
    protected abstract IReadOnlyList<CinemachineVirtualCameraBase> CameraCandidates { get; }
    public CinemachineCamera LiveCmCamera => LiveChild as CinemachineCamera;

    protected virtual void Awake()
    {

    }

    protected override void Start()
    {
        base.Start();
    }

    protected abstract override CinemachineVirtualCameraBase ChooseCurrentCamera(Vector3 worldUp, float deltaTime);

    public virtual void GetInputAxes(List<IInputAxisOwner.AxisDescriptor> axes)
    {
        
    }

    //우선순위 제일 높은 카메라를 가져옴
    protected CinemachineVirtualCameraBase GetHighestPriorityCamera()
    {
        // 자식에서 할당한 카메라들
        IReadOnlyList<CinemachineVirtualCameraBase> candidates = CameraCandidates;
        if (candidates == null) return null;

        CinemachineVirtualCameraBase highest = null;
        float maxPrio = float.MinValue;

        foreach (CinemachineVirtualCameraBase cam in candidates)
        {
            if (cam != null && cam.Priority.Value > maxPrio)
            {
                maxPrio = cam.Priority.Value;
                highest = cam;
            }
        }
        return highest;
    }
}
