using System;
using System.Runtime.CompilerServices;
using UniRx;
using UnityEngine;
using UnityEngine.EventSystems;

public class CornSeedlingView : MonoBehaviour
{
    [SerializeField] private GameObject growingArrowPrefab;

    [SerializeField] private CornSeedlingStageView seedling1;
    [SerializeField] private CornSeedlingStageView seedling2;
    [SerializeField] private CornSeedlingStageView seedling3;

    private CornSeedlingStageView currentSeedling;
    
    public CornSeedlingStageView GetStageView(CornFieldRank rank)
    {
        seedling1.gameObject.SetActive(rank == CornFieldRank.Rank1);
        seedling2.gameObject.SetActive(rank == CornFieldRank.Rank2);
        seedling3.gameObject.SetActive(rank == CornFieldRank.Rank3);
        switch (rank)
        {
            case CornFieldRank.Rank1:
                return seedling1;
            case CornFieldRank.Rank2:
                return seedling2;
            case CornFieldRank.Rank3:
                return seedling3;
            default:
                throw new ArgumentOutOfRangeException(nameof(rank), rank, null);
        }
    }

    public void SetView(CornFieldRank rank, SeedlingStage stage)
    {
        currentSeedling = GetStageView(rank);
        currentSeedling.SetView(stage);
    }

    public void ChangeState(SeedlingStage stage)
    {
        currentSeedling.ChangeState(stage);
    }

    public void EffectGrowth()
    {
        var arrow = Instantiate(growingArrowPrefab, transform);
        this.CallWaitForSeconds(0.5f, () => Destroy(arrow));
    }
}