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.Actors
{
    public class EnemySongResponder : SongResponder
    {
        public class ExposeFreeze : CoreAction
        {
            public bool freeze;

            public ExposeFreeze(bool freeze)
            {
                this.freeze = freeze;
            }
        }

        private UnityTimer freezeTimer;

        // Use this for initialization
        protected override void InnerAwake()
        {
            AddActionHandler<PowerMelody.SongEffectAction>(Freeze);
        }

        // Update is called once per frame
        protected override void InnerUpdate()
        {
            if (this.freezeTimer != null)
            {
                if(!this.freezeTimer.IsComplete())
                {
                    this.freezeTimer.Advance();
                }
                if (this.freezeTimer.IsComplete())
                {
                    //Debug.Log("Un freeze");
                    Interact(new ExposeFreeze(false));
                    this.freezeTimer.Reset();
                    this.freezeTimer = null;
                }
            }
           
        }

        private void Freeze(PowerMelody.SongEffectAction action)
        {
            if (this.freezeTimer == null)
            {
                //Debug.Log("Song responder receieved freeze");
                Interact(new ExposeFreeze(true));
                this.freezeTimer = new UnityTimer(action.freezeTime, false);
            }
        }
    }
}
