using Patterns_And_Principles.Patterns.The_State_Pattern.Script._02_RealWorldUsage.Manager;
using UnityEngine;

namespace Patterns_And_Principles.Patterns.The_State_Pattern.Script._02_RealWorldUsage.State
{
    public class AppleWholeState : AppleBaseState
    {
        private float _rottenTime = 6f;
        public override void EnterState(AppleStateManager appleStateManager)
        {
            Debug.Log("Entered AppleWholeState");
            appleStateManager.GetComponent<Rigidbody>().useGravity = true;
        }

        public override void UpdateState(AppleStateManager appleStateManager)
        {
            if (_rottenTime > 0)
            {
                _rottenTime -= Time.deltaTime;
            }
            else
            {
                appleStateManager.SwitchState(appleStateManager._rottenState);
            }
        }

        public override void OnCollisionEnter(AppleStateManager appleStateManager, Collision collision)
        {
            GameObject obj = collision.gameObject;
            if (obj.CompareTag("Player")) //
            {
                Debug.Log("Apple Ate");
                appleStateManager.SwitchState(appleStateManager._chewedState);
            }
        }
    }
}