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

public class EachRewardBtn : MonoBehaviour
{
    public EachLeaguePlace myLeague;
    public Text txtName;

    public string RewardId;
    public string rewName;
    public string des;
    public string logoAdd;
    public string rewardName;
    public string myCount;
    public string kind;
    public string flname;
    public string leagueCount;

    void Start()
    {
       
    }

    public void SetReward()
    {
        myLeague.adok.OnSetRewardChange += Adok_OnSetRewardChange;
        myLeague.adok.SetReward(RewardId, myLeague.leagueId, leagueCount);
    }

    private void Adok_OnSetRewardChange(ADokManager.SetRewardResults SetRewardResults)
    {
        
        myLeague.txtResult.text = "SetRewardResults: " + SetRewardResults.ToString();

        switch (SetRewardResults)
        {
            case ADokManager.SetRewardResults.NotInitialized:
                myLeague.adok.OnSetRewardChange -= Adok_OnSetRewardChange;
                break;
            case ADokManager.SetRewardResults.success:
                myLeague.adok.OnSetRewardChange -= Adok_OnSetRewardChange;
                if (int.Parse(kind) >= 0)
                {
                    string fl = myLeague.adok.GetData(flname);
                    float val = 0;
                    if (fl != "none")
                    {
                        val = float.Parse(fl);
                    }
                    val += float.Parse(myCount);
                    myLeague.adok.SetData(flname, val.ToString(), ADokManager.SyncType.Sync);
                }
                break;
            case ADokManager.SetRewardResults.Fail:
                myLeague.adok.OnSetRewardChange -= Adok_OnSetRewardChange;
                break;
            case ADokManager.SetRewardResults.none:
                break;
            case ADokManager.SetRewardResults.Loading:
                break;
            case ADokManager.SetRewardResults.GetBefore:
                myLeague.adok.OnSetRewardChange -= Adok_OnSetRewardChange;
                break;
        }
    }
}
