﻿namespace Stove.StoveSDK
{
    using System;
    using System.Collections.Generic;
    using UnityEngine;

    /**
     * TermsOfService UI provided by the Stove.
     * @since 2.0.0
     */
    public class TermsOfServiceUI
    {
        /**
         * Provides the ability to display screens for terms and conditions for agree.
         *
         * If the user agrees to all the terms, it returns an empty map.
         *
         * @param action Agree Result.
         * @since 2.0.0
         */
        public static void Agree(Action<Result, List<TermsOfServiceData>> action)
        {
            Debug.Log("TermsOfServiceUI.Agree");
            string identifier = StoveSDK.Instance.AddAction(payload =>
            {
                Result result = new Result(payload["result"] as Dictionary<string, object>);
                List<TermsOfServiceData> list = new List<TermsOfServiceData>();
                List<object> termsOfServiceDataList = payload["termsOfServiceDataList"] as List<object>;
                foreach (object obj in termsOfServiceDataList)
                {
                    TermsOfServiceData termsOfServiceData = new TermsOfServiceData(obj as Dictionary<string, object>);
                    list.Add(termsOfServiceData);
                }
                Debug.Log("TermsOfServiceUI.Agree Result(" + result + "), list(" + list + ")");
                action.Invoke(result, list);
            });
            AuthUIInterface.Agree(identifier);
        }

        /**
         * Provides the ability to display screens for terms and conditions for register.
         *
         * If the user agrees to all the terms, it returns an empty map.
         *
         * @param action Agree Result.
         * @since 2.0.0
         */
        public static void AgreeForRegister(Action<Result, List<TermsOfServiceData>> action)
        {
            Debug.Log("TermsOfServiceUI.AgreeForRegister");
            string identifier = StoveSDK.Instance.AddAction(payload =>
            {
                Result result = new Result(payload["result"] as Dictionary<string, object>);
                List<TermsOfServiceData> list = new List<TermsOfServiceData>();
                List<object> termsOfServiceDataList = payload["termsOfServiceDataList"] as List<object>;
                foreach (object obj in termsOfServiceDataList)
                {
                    TermsOfServiceData termsOfServiceData = new TermsOfServiceData(obj as Dictionary<string, object>);
                    list.Add(termsOfServiceData);
                }
                Debug.Log("TermsOfServiceUI.AgreeForRegister Result(" + result + "), list(" + list + ")");
                action.Invoke(result, list);
            });
            AuthUIInterface.AgreeForRegister(identifier);
        }

        /**
         * Provides the ability to display screens for terms and conditions for register.
         *
         * If the user agrees to all the terms, it returns an empty map.
         *
         * @param provider Current provider.
         * @param action Agree Result.
         * @since 2.3.2
         */
        public static void AgreeForRegister(Provider provider, Action<Result, List<TermsOfServiceData>> action)
        {
            Debug.Log("TermsOfServiceUI.AgreeForRegister Provider(" + provider + "), Action(" + action + ")");
            string identifier = StoveSDK.Instance.AddAction(payload =>
            {
                Result result = new Result(payload["result"] as Dictionary<string, object>);
                List<TermsOfServiceData> list = new List<TermsOfServiceData>();
                List<object> termsOfServiceDataList = payload["termsOfServiceDataList"] as List<object>;
                foreach (object obj in termsOfServiceDataList)
                {
                    TermsOfServiceData termsOfServiceData = new TermsOfServiceData(obj as Dictionary<string, object>);
                    list.Add(termsOfServiceData);
                }
                Debug.Log("TermsOfServiceUI.AgreeForRegister Result(" + result + "), list(" + list + ")");
                action.Invoke(result, list);
            });
            AuthUIInterface.AgreeForRegisterProvider(provider.ClassName, identifier);
        }
    }
}
