using UnityEngine;
using Zenject;
using FlappyBird.Core;
namespace FlappyBird.Gameplay.Pipes
{
    /// <summary>
    /// Thin MonoBehaviour placed on a trigger-collider child of the pipe-pair prefab.
    /// Sits in the centre of the gap. When the bird passes through it fires OnPlayerScored,
    /// which the ScoreManager listens to.
    /// NO scoring logic lives here — only trigger detection and event dispatch.
    /// </summary>
    [RequireComponent(typeof(Collider2D))]
    public sealed class ScoreTriggerView : MonoBehaviour
    {
        /// <summary>
        /// Fired when the bird's collider enters this trigger.
        /// Subscribers (ScoreManager via installer) add the score.
        /// </summary>
        public event System.Action OnPlayerScored;
        private IScoreManager _scoreManager;
        [Inject]
        private void Construct(IScoreManager scoreManager)
        {
            _scoreManager = scoreManager;
        }
        private void OnTriggerEnter2D(Collider2D other)
        {
            // Only react to the bird layer — avoids double-counting with pipe colliders.
            if (!other.CompareTag("Bird")) return;
            OnPlayerScored?.Invoke();
            _scoreManager.AddScore(1);
        }
    }
}