using System;
using UniRx;
using UnityEngine;
using UnityEngine.UI;

public class FacilityExpantionItem : MonoBehaviour
{
    [SerializeField] private PlantLineType type;
    [SerializeField] private Text text;
    [SerializeField] private Text buttonText;
    [SerializeField] private Button button;
    public PlantLineType Type => type; 
    public IObservable<Unit> ClickObservable => button.OnClickAsObservable();
    private readonly ReactiveProperty<bool> isAvailable = new ReactiveProperty<bool>();

    private void Start()
    {
        isAvailable.AddTo(this);
        isAvailable.SubscribeToInteractable(button);
    }

    public void SetItem(bool hasField, CornFieldRank level)
    {
        if (hasField)
        {
            // 強化
            buttonText.text = GetButtonText(level);
            text.text = GetLevelUpText(level);
        }
        else
        {
            // 畑の拡張
            buttonText.text = $"購入";
            text.text = $"畑を拡張します\n収穫できる株が４つ増えます";
        }
    }

    public void SetCoin(int coin)
    {
    }

    private string GetButtonText(CornFieldRank level)
    {
        switch (level)
        {
            case CornFieldRank.Rank1:
            case CornFieldRank.Rank2:
            case CornFieldRank.Rank3:
                return $"購入";
            default:
                throw new ArgumentOutOfRangeException(nameof(level), level, null);
        }
    }

    private string GetLevelUpText(CornFieldRank level)
    {
        switch (level)
        {
            case CornFieldRank.Rank1:
                return $"畑の質を強化\nx1 -> x2";
            case CornFieldRank.Rank2:
                return $"畑の質を強化\nx2 -> x3";
            case CornFieldRank.Rank3:
                return $"最大値です";
            default:
                throw new ArgumentOutOfRangeException(nameof(level), level, null);
        }
    }
}
