/********************\
|  Copyright 2024,   |
|       Ulysse Cura  |
\********************/

//////////////////////////////////////////////////
//                                              //
//   Composant interactif, ici pour les levier. //
//                                              //
//////////////////////////////////////////////////

#ifndef LEVER_HPP
#define LEVER_HPP

#include "AnimationSystem.hpp"
#include "InteractableComponent.hpp"
#include "../Game.hpp"

class Lever : public InteractableComponent {
  public:
    Lever(int channel) : m_channel(channel)
    {}

    void init() override
    {
        m_animation = &entity->getComponent<AnimationSystem>();
        m_animation->loop = false;
    }

    void update() override
    {
        if(!m_animation->playAnimation)
        {
            Game::entityManager.getChannelManager().setChannel(m_channel, m_leverOn);
        }
    }

    void interact() override
    {
        if(!m_animation->playAnimation)
        {
            if(m_leverOn)
            {
                m_animation->reverse = true;
                m_animation->playAnimation = true;

                m_leverOn = false;
            }
            else
            {
                m_animation->reverse = false;
                m_animation->playAnimation = true;

                m_leverOn = true;
            }
        }
    }

  private:
    int m_channel;

    AnimationSystem *m_animation;

    bool m_leverOn {false};
};

#endif
