using System;
using UnityEngine;

public class PopcornGameView : MonoBehaviour
{
    [SerializeField] private GameObject startingGuide;
    [SerializeField] private GameObject fire;
    [SerializeField] private GameObject oilEffect;
    [SerializeField] private GameObject streamEffect;
    [SerializeField] private GameObject characterSweat;
    [SerializeField] private GameObject characterFlower;
    [SerializeField] private Transform panImageTarget;

    public void ChangeUI(GameState state)
    {
        switch (state)
        {
            case GameState.TutorialBeforeGuide:
                SoundManager.Instance.StopSELoop("se_cooking_corn_bake");
                ChangeGuideState(false);
                ChangeFireState(false);
                ChangeStreamState(false);
                ChangeCharacterState(ThermalCondition.Cold);
                break;
            case GameState.Guide:
                SoundManager.Instance.StopSELoop("se_cooking_corn_bake");
                ChangeGuideState(true);
                ChangeFireState(false);
                ChangeStreamState(false);
                ChangeCharacterState(ThermalCondition.Cold);
                break;
            case GameState.Playing:
                SoundManager.Instance.PlaySELoop("se_cooking_corn_bake");
                ChangeGuideState(false);
                ChangeFireState(true);
                break;
            case GameState.Result:
                SoundManager.Instance.StopSELoop("se_cooking_corn_bake");
                ChangeFireState(false);
                ChangeStreamState(true);
                ChangeCharacterState(ThermalCondition.Cold);
                break;
            default:
                throw new ArgumentOutOfRangeException(nameof(state), state, null);
        }
    }
    
    private void ChangeGuideState(bool isActive)
    {
        startingGuide.SetActive(isActive);
    }

    private void ChangeFireState(bool isActive)
    {
        if (isActive)
        {
            SoundManager.Instance.PlaySE("se_cooking_switch");
        }
        fire.SetActive(isActive);
        oilEffect.SetActive(isActive);
    }

    private void ChangeStreamState(bool isActive)
    {
        streamEffect.SetActive(isActive);
    }

    public void ChangeCharacterState(ThermalCondition condition)
    {
        switch (condition)
        {
            case ThermalCondition.Cold:
                characterFlower.gameObject.SetActive(false);
                characterSweat.gameObject.SetActive(false);
                break;
            case ThermalCondition.Yellow:
                characterFlower.gameObject.SetActive(true);
                characterSweat.gameObject.SetActive(false);
                break;
            case ThermalCondition.Hot:
                characterFlower.gameObject.SetActive(false);
                characterSweat.gameObject.SetActive(true);
                break;
            default:
                throw new ArgumentOutOfRangeException(nameof(condition), condition, null);
        }
    }

    public void SetPan(Transform prefab)
    {
        panImageTarget.DestroyAllChildrens();
        Instantiate(prefab, panImageTarget);
    }
}
