using System;
using UnityEngine;
using UnityEngine.Animations;

public class EnemyAnimation : MonoBehaviour
{
    private Animator _animator;
    private EnemyCombat _combat;
    
    private static readonly int ApproachHash = Animator.StringToHash("IsChasingThePlayer");
    private static readonly int IdleHash = Animator.StringToHash("IsIdle");
    private static readonly int BlockHash = Animator.StringToHash("Block");
    private static readonly int AttackHash = Animator.StringToHash("Attack");
    private static readonly int ThrowHash = Animator.StringToHash("Throw");
    private static readonly int StunHash = Animator.StringToHash("Stun");
    private static readonly int DeathHash = Animator.StringToHash("Death");
    private void Awake()
    {
        _animator = GetComponent<Animator>();
        _combat = GetComponentInParent<EnemyCombat>();
    
        if (_combat == null) Debug.LogError("EnemyAnimation could not find EnemyCombat in parent!");
    }

    public void UpdateIdleState(bool isIdle)
    {
        _animator.SetBool(IdleHash, isIdle);
    }

    public void UpdateApproachState(bool isChasingThePlayer)
    {
        _animator.SetBool(ApproachHash, isChasingThePlayer);
    }

    public void SetAttackTrigger()
    {
        _animator.SetTrigger(AttackHash);
    }

    public void SetStunTrigger()
    {
        _animator.SetTrigger(StunHash);
    }
    public void SetThrowTrigger()
    {   
        _animator.SetTrigger(ThrowHash);
    }
    public void SetBlockTrigger()
    {
        _animator.SetTrigger(BlockHash);
    }

    public void SetDeathTrigger()
    {
        _animator.SetTrigger(DeathHash);
    }

    public void DealDamage() => _combat.DealDamage();

    public void EndAttack() => _combat.EndAttack();

    public void EndBlock() => _combat.EndBlock();

    public void EndStun() => _combat.EndStun();
}
