using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UniRx;
using UnityEngine;
using UnityEngine.UI;

public class KitchenManager : MonoBehaviour
{
    [SerializeField] private Button cookingButton;
    [SerializeField] private TankListView tankListView;
    // Start is called before the first frame update
    void Start()
    {
        // レシピの表示
        cookingButton.OnClickAsObservable().Subscribe(_ =>
        {
            // TransitionManager.Instance.LoadScene(GameScenes.Cooking);
            TransitionManager.Instance.LoadSceneAdditive(GameScenes.Recipe);
        });
        
        // スプレッドシート対応
        // レシピIDが一覧で入っている
        // データ
        var gameData = GameDataManager.GameData;
        CoinManager.Instance.ChangeCoin(gameData.coin);
        
        SetData();

        // 在庫表示
        tankListView.SetTanksView(gameData.StorageTanks);

        Market.StockFlavorLog();
    }

    private void SetData()
    {
        var gameData = GameDataManager.GameData;
        // 所持レシピ
        gameData.MyRecipes = new[]
        {
            1,
            2,
            13,
        };
        
        // 所持素材
        if (gameData.Material == null || gameData.Material.Count == 0)
        {
            gameData.Material = Enumerable.Range(1, 12).Select(x => new MaterialData(x, 0)).ToList();
        }

        // 店頭ストック
        if (gameData.ShopStock == null)
        {
            gameData.ShopStock = new List<int>();
        }
        // 保存タンク
        if (gameData.StorageTanks == null || gameData.StorageTanks.Count == 0)
        {
            gameData.StorageTanks = new List<StorageTank>
            {
                new StorageTank
                {
                    Id = 1,
                    Capacity = 50,
                    FlavorId = -1,
                    Stock = 0,
                    BonusRate = 0
                }
            };
        }
        GameDataManager.SaveGameData();
    }
}
