using UnityEngine;

public class EnemyEntity : Entity
{
    [SerializeField] private EnemyConfig config;
    [SerializeField] private EnemyBrain enemyBrain;
    
    public EnemyConfig Config => config;
    public EnemyBrain Brain => enemyBrain;

    private PlayerCombat player;
    
    protected override void Awake()
    {
        base.Awake();
        if (health != null && config != null)
            health.SetMaxHealth(config.maxHealth);
        
        enemyBrain.Initialize(this, Config);
        
        player = GameObject.FindWithTag("Player").GetComponent<PlayerCombat>();
    }
    
    private void OnEnable()
    {
        if(EnemyCoordinator.Instance != null) EnemyCoordinator.Instance.RegisterEnemy(Brain);
    }

    private void OnDisable()
    {
        if(EnemyCoordinator.Instance != null) EnemyCoordinator.Instance.DeregisterEnemy(Brain);
        player.OnEnemyDefeat();
    }
    
}
