using FlappyBird.Core;
using UnityEngine;

namespace FlappyBird.Pipes
{
    public class PipeScoreTrigger : MonoBehaviour
    {
        private IScoreManager _scoreManager;
        private bool _canScore;

        public void Initialize(IScoreManager scoreManager)
        {
            _scoreManager = scoreManager;
        }

        public void ResetTrigger()
        {
            _canScore = true;
        }

        private void OnTriggerEnter2D(Collider2D other)
        {
            if (!_canScore || _scoreManager == null)
            {
                return;
            }

            if (!other.CompareTag("Player"))
            {
                return;
            }

            _canScore = false;
            _scoreManager.AddScore(1);
        }
    }
}
