using KitsuneCafe.Sys.Attributes;
using UnityEngine;

namespace KitsuneCafe.Animation
{
    public class TriggerAnimation : MonoBehaviour
    {
        [SerializeField]
        private Animator animator;

        [SerializeField, AnimatorParam("animator")]
        private int parameter;

        private void Reset()
        {
            animator = GetComponent<Animator>();
        }

        public void SetValue(int parameter, bool value)
        {
            animator.SetBool(parameter, value);
        }

        public void SetValue(string parameter, bool value)
        {
            SetValue(Animator.StringToHash(parameter), value);
        }

        public void SetValue(bool value)
        {
            SetValue(parameter, value);
        }

        public void SetValue(int parameter, int value)
        {
            animator.SetInteger(parameter, value);
        }

        public void SetValue(string parameter, int value)
        {
            SetValue(Animator.StringToHash(parameter), value);
        }

        public void SetValue(int value)
        {
            SetValue(parameter, value);
        }

        public void SetValue(int parameter, float value)
        {
            animator.SetFloat(parameter, value);
        }

        public void SetValue(string parameter, float value)
        {
            SetValue(Animator.StringToHash(parameter), value);
        }

        public void SetValue(float value)
        {
            SetValue(parameter, value);
        }

        public void Trigger(string parameter)
        {
            Trigger(Animator.StringToHash(parameter));
        }

        public void Trigger(int parameter)
        {
            switch (animator.GetParameter(parameter).type)
            {
                case AnimatorControllerParameterType.Trigger:
                    animator.SetTrigger(parameter);
                    break;
                case AnimatorControllerParameterType.Bool:
                    var value = animator.GetBool(parameter);
                    animator.SetBool(parameter, !value);
                    break;
            }
        }

        public void Trigger()
        {
            Trigger(parameter);
        }
    }
}
