using System;
using UnityEngine;

public class LeverInteractables : MonoBehaviour, IInteractable
{
    [SerializeField] GameObject interactingObject;

    bool isActive = false;
    public bool IsActive => isActive;

    public event Action<bool> onLeverActivate;
    public void OnLeverActivate(bool trigger)
    {
        if (onLeverActivate != null)
        {
            onLeverActivate(trigger);
        }
    }

    AudioSource audioSource;
    Animator animator;

    private void Awake()
    {
        audioSource = GetComponent<AudioSource>();
        animator = GetComponent<Animator>();
    }

    public void InteractWithObject()
    {
        animator.SetTrigger("Down");

        ILeverMoveable moveable = interactingObject.GetComponent<ILeverMoveable>();

        if (moveable != null)
        { moveable.MoveObject(); }

        OnLeverActivate(IsActive);
    }

    public void SoundEffect()
    {
        audioSource.Play();
    }
}
