using UnityEngine;

namespace AsteroidGame.Entities
{
    public class Turret : StructureBase
    {
        [Header("WeaponParameters")]
        [SerializeField] private int _damage = 1;
        [SerializeField] private float _fireRate = 1;
        [SerializeField] private float _projectileSpeed = 5;

        [Header("Stats")]
        [SerializeField] private float _kills = 0f;
        [SerializeField] private float _damageDealt = 0f;

        [Header("RigConnections")]
        [SerializeField] private Transform _turretHead;
        [SerializeField] private Transform _barrel;

        [field: Header("Targeter")]
        [field: SerializeField] public Targeter Targeter { get; set; }

        #region Publics

        public int Damage
        {
            get => _damage;
            set => _damage = value;
        }

        #endregion

        protected override void OnEnable()
        {
            base.OnEnable();
            InitializeTargeter();
        }

        private void InitializeTargeter()
        {
            Targeter.SetParent(Targetable);
        }

        private void Update()
        {
            if (!Targeter.FoundTarget()) return;
            _turretHead.transform.LookAt(Targeter.GetTarget().GetCenterPosition());
        }
    }
}