using UnityEngine;
using Stove.StoveSDK;
using System.Collections.Generic;

public class PushSample : MonoBehaviour
{
    void Start()
    {
    }

    void Update()
    {
    }

    public void RegisterPush()
    {
        TextFieldOneDialog.Show((deviceToken) =>
        {
            if (deviceToken != null)
            {
                Debug.Log("------- [Stove-Sample] Push.RegisterPush -------");

                Push.RegisterPush(deviceToken, (Result result) =>
                {
                    Debug.Log("------- [Stove-Sample] Push.RegisterPush : " + result + " -------");

                    if (result.IsSuccessful)
                    {
                        SSTools.ShowMessage("Push.RegisterPush Success", SSTools.Position.bottom, SSTools.Time.oneSecond);
                    }
                    else
                    {
                        SSTools.ShowMessage("Push.RegisterPush Fail", SSTools.Position.bottom, SSTools.Time.oneSecond);
                    }
                });
            }
            else
            {
                // cancel
            }
        });
    }

    public void FetchPushSettings()
    {
        Debug.Log("------- [Stove-Sample] Push.FetchPushSettings -------");

        Push.FetchPushSettings((Result result, PushSettings pushSettings) =>
        {
            Debug.Log("------- [Stove-Sample] Push.FetchPushSettings : " + result + " -------");

            if (result.IsSuccessful)
            {
                SSTools.ShowMessage("Push.FetchPushSettings Success", SSTools.Position.bottom, SSTools.Time.oneSecond);
            }
            else
            {
                SSTools.ShowMessage("Push.FetchPushSettings Fail", SSTools.Position.bottom, SSTools.Time.oneSecond);
            }
        });
    }

    public void UpdatePushSettings()
    {
        PushSettingsDialog.Show((enabledDay, enabledNight) =>
        {
            if (enabledDay == null && enabledNight == null)
            {
                // cancel
            }
            else
            {
                Debug.Log("------- [Stove-Sample] Push.UpdatePushSettings -------");

                PushSettings settings = new PushSettings(enabledDay, enabledNight);
                Push.UpdatePushSettings(settings, (Result result, PushSettings pushSettings) =>
                {
                    Debug.Log("------- [Stove-Sample] Push.UpdatePushSettings : " + result + " -------");

                    if (result.IsSuccessful)
                    {
                        SSTools.ShowMessage("Push.UpdatePushSettings Success", SSTools.Position.bottom, SSTools.Time.oneSecond);
                    }
                    else
                    {
                        SSTools.ShowMessage("Push.UpdatePushSettings Fail", SSTools.Position.bottom, SSTools.Time.oneSecond);
                    }
                });
            }
        });
    }

    public void SetMessageDelegate()
    {
        Debug.Log("------- [Stove-Sample] Push.SetMessageDelegate -------");

        Push.SetMessageDelegate((Dictionary<string, string> dictionary) =>
        {
            Debug.Log("------- [Stove-Sample] Push.SetMessageDelegate : " + dictionary + " -------");
        });
    }

    public void Version()
    {
        SSTools.ShowMessage("Push Version : " + Push.GetVersion(), SSTools.Position.bottom, SSTools.Time.oneSecond);
    }
}
