using System;
using System.Threading.Tasks;
using UnityEngine;

namespace tysdk
{
    public partial class TYSdkFacade : MonoBehaviour
    {
        /*================================================

                                _  _____ _____ 
                               / \|_   _|_   _|
                              / _ \ | |   | |  
                             / ___ \| |   | |  
                            /_/   \_\_|   |_|  
                                               
      =================================================*/

        public bool IsAttAccepted()
        {
            return UnityBridgeFunc.GetATT() == 1;
        }

        public async Task<ATTInfo> RequestATT()
        {
#if UNITY_EDITOR || UNITY_ANDROID
            await Task.Yield();

            return new ATTInfo(){isAccepted = true};
#elif UNITY_IOS
          var task = tysdk.TYSDKCallbackManager.Instance.RegisterCallback<ATTInfo>();
            UnityBridgeFunc.RequestATT();
            try{
              return await task;
            }
            catch(Exception e)
            {
              Debug.LogWarning(e.Message);
              return new ATTInfo(){isAccepted = false};
            }
#endif
        }

        public void RequestATTResult(string r)
        {
            TYSDKCallbackManager.Instance.TryTriggerCallback(new ATTInfo(){isAccepted = r == "1"});
        }
    }
}
