using System.Text;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class AFInit
{
    public Text text {get; set;}

    [Btn("Clear")]
    public void Clear()
    {
        text.text = "";
    }

    public void InitAF()
    {
    }

    [Btn("Gen Url")]
    public async void GenInviteUrl()
    {
        var url = await AFDeepLinkHelper.Instance.GenInviteLink("Mustapha", "123456");
        if(url != null)
        {
            Debug.Log($"[AFInit::GenInviteUrl] {url}");
            text.text = $"{url}\n";
        }
        else
        {
            text.text = $"Error\n";
        }
    }

    [Btn("DeepLinkData")]
    public void DeepLinkData()
    {
        if(AFDeepLinkHelper.Instance.DidReceivedDeepLink)
        {
            var sb = new StringBuilder();
            sb.Append($"DeepLinkData \n");
            foreach(var item in AFDeepLinkHelper.Instance.DeepLinkParamsDictionary)
            {
                sb.Append($"{item.Key} : {item.Value}\n");
                sb.AppendLine();
            }
            var data =  sb.ToString();
            text.text = data;
            Debug.Log($"[AFInit::DeepLinkData]\r\n{data}");
        }
        else
            text.text = $"No DL\n";
    }

    [Btn("Referrer")]
    public void Referer()
    {
        if(AFDeepLinkHelper.Instance.GetDLReferer(out string pid, out string uid))
        {
            text.text = $"Referrer  pid:{pid} uid:{uid}\n";
        }
        else
        {
            text.text = $"No Referrer\n";
        }
    }

    [Btn("SDK Test")]
    public void SDKTest()
    {
        SceneManager.LoadScene("SampleScene");
    }

}
