using UnityEngine;

public class InteruptMoulin : InteractableObject {

    public static bool isOn = false;
    private static ParticleSystem etincel;

    private static Vector3 isOnPos = new Vector3(-45.255f, 29.29274f, 58.0531f);
    private static Vector3 isOnRot = new Vector3(1.939224f, -25.84357f, -1.847137f);

    private static Vector3 isOffPos = new Vector3(-45.2581f, 29.292f, 58.0498f);
    private static Vector3 isOffRot = new Vector3(1.919998f, -24.82361f, -62.26602f);

    protected override void Start() {
        base.Start();
        etincel = transform.parent.GetComponentInChildren<ParticleSystem>();
    }

    protected override void DoActionDown() {
        Switch();
        SoundManager.PlaySound("switch");
    }

    void UpdateTransform() {
        transform.position = (isOn ? isOnPos : isOffPos);
        transform.eulerAngles = (isOn ? isOnRot : isOffRot);
    }
    void Switch() {
        isOn = !isOn;
        if (isOn) {
            RotateMoulin.RotateOn();
            if (etincel != null) {
                etincel.Play();
            }
            BoutonPupitreMoulin.UpdateEtincelle();
        } else {
            RotateMoulin.RotateOff();
            if (etincel != null) {
                etincel.Stop();
            }
        }
        
        UpdateTransform();
    }
    protected override void Update()
    {
        base.Update();
        if (BoutonPupitreMoulin.win)
        {
            Interupt.thereIsElectricity = isOn;
        } 
    }
}