using Framework.Entities;
using Framework.Utility;
using Project.Player;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Project.Effects
{
    public class WaveMachine : CoreBehaviour
    {
        public AudioClip wave1Clip;
        public AudioClip wave2Clip;
        private UnityTimer wave1Timer;
        private UnityTimer wave2Timer;
        private UnityTimer endTimer;
        private bool end = false;

        protected override void InnerAwake()
        {
            AddGlobalActionHandler<PlayerInput.UnfreezeInputAction>(this, (PlayerInput.UnfreezeInputAction action) => {this.end = true;}); 
            this.wave1Timer = new UnityTimer(3.2f, true);
            this.wave2Timer = new UnityTimer(6f, false);
            this.endTimer = new UnityTimer(2f, false);
        }

        protected void Update()
        {
            this.wave1Timer.Advance();
            if (this.wave1Timer.IsComplete())
            {
                AudioSource.PlayClipAtPoint(wave1Clip, Vector3.zero);
                this.wave1Timer.Reset();
            }
            this.wave2Timer.Advance();
            if (this.wave2Timer.IsComplete())
            {
                AudioSource.PlayClipAtPoint(wave2Clip, Vector3.zero);
                this.wave2Timer.Reset();
            }

            if (this.end)
            {
                this.endTimer.Advance();
                if (this.endTimer.IsComplete())
                {
                    Debug.Log("Quit");
                    Application.Quit();
                }
            }
        }
    }
}
