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

namespace Patterns_And_Principles.Patterns.The_State_Pattern.Script._02_RealWorldUsage.Manager
{
    public class AppleStateManager : MonoBehaviour
    {
        private AppleBaseState _currentState;
        public AppleGrowingState _growingState = new AppleGrowingState();
        public AppleChewedState _chewedState = new AppleChewedState();
        public AppleRottenState _rottenState = new AppleRottenState();
        public AppleWholeState _wholeState = new AppleWholeState();

        private void OnCollisionEnter(Collision other)
        {
            _currentState.OnCollisionEnter(this, other);
        }

        private void Start()
        {
            //Start state machine 
            _currentState = _growingState;
            _currentState.EnterState(this);
        }

        private void Update()
        {
            _currentState.UpdateState(this);
        }

        public void SwitchState(AppleBaseState newState)
        {
            _currentState = newState;
            newState.EnterState(this);
        }
    }
}