using System;
using UnityEngine;

namespace EngineSdkConverter.Unity.SDK
{
    /// <summary>
    /// AIHelp事件类型
    /// </summary>
    public enum AiHelpEventType {
        /**
        * Event for SDK initialization
        */
        INITIALIZATION,

        /**
        * Event for user login
        */
        USER_LOGIN,

        /**
        * Event for enterprise authentication
        */
        ENTERPRISE_AUTH,

        /**
        * Event for opening or closing a session (window)
        */
        SESSION_OPEN,
        SESSION_CLOSE,

        /**
        * Event for message arrival
        */
        MESSAGE_ARRIVAL,

        /**
        * Event for log upload
        */
        LOG_UPLOAD,

        /**
        * Event for URL click
        */
        URL_CLICK
    }

    /// <summary>
    /// AIHelp初始化参数
    /// </summary>
    public class AIHelpInitType
    {
        public bool isInIndia;
        public bool isInChinaMainland;

        public AIHelpInitType(bool isInIndia, bool isInChinaMainland)
        {
            this.isInIndia = isInIndia;
            this.isInChinaMainland = isInChinaMainland;
        }
    }


    /// <summary>
    /// AIHelp事件回调
    /// </summary>
    #if UNITY_ANDROID
    public class AIHelpCallback : AndroidJavaProxy
    {
        public AIHelpCallback() : base("com.tuyoo.sdk.sdk_inter_layer.interfaces.RegisterAiHelpAsyncEventListener") { }

        public Action<string, object> onAsyncEventReceivedCallback;

        public void onEvent(string jsonData, AndroidJavaObject ignored)
        {
            Debug.Log($"AIHelp event received: {jsonData}");
            NativeCallBack.Enqueue(() =>
            {
                onAsyncEventReceivedCallback?.Invoke(jsonData, ignored);
            });
        }
    }
    #endif
    
    /// <summary>
    /// AIHelp显示参数
    /// </summary>
    public class AIHelpShowTypeBuilder
    {
        public class AIHelpShowType
        {
            public string entranceId;
            public string welcomeMsg;
        }

        private AIHelpShowType _aihelpShowType;

        public AIHelpShowTypeBuilder()
        {
            _aihelpShowType = new AIHelpShowType();
        }

        public AIHelpShowTypeBuilder SetEntranceId(string entranceId)
        {
            _aihelpShowType.entranceId = entranceId;
            return this;
        }

        public AIHelpShowTypeBuilder SetWelcomeMsg(string welcomeMsg)
        {
            _aihelpShowType.welcomeMsg = welcomeMsg;
            return this;
        }

        public AIHelpShowType Build()
        {
            return _aihelpShowType;
        }
    }

    /// <summary>
    /// AIHelp设置登录用户信息参数
    /// </summary>
    public class AIHelpSetLoginUserInfoTypeBuilder
    {
        public class AIHelpSetLoginUserInfoType
        {
            public string userId;
            public string serverId;
            public string userName;
            public string customData;
            public string tag;
        }

        private AIHelpSetLoginUserInfoType _aihelpSetLoginUserInfoType;

        public AIHelpSetLoginUserInfoTypeBuilder()
        {
            _aihelpSetLoginUserInfoType = new AIHelpSetLoginUserInfoType();
        }

        public AIHelpSetLoginUserInfoTypeBuilder SetUserId(string userId)
        {
            _aihelpSetLoginUserInfoType.userId = userId;
            return this;
        }

        public AIHelpSetLoginUserInfoTypeBuilder SetServerId(string serverId)
        {
            _aihelpSetLoginUserInfoType.serverId = serverId;
            return this;
        }

        public AIHelpSetLoginUserInfoTypeBuilder SetUserName(string userName)
        {
            _aihelpSetLoginUserInfoType.userName = userName;
            return this;
        }

        public AIHelpSetLoginUserInfoTypeBuilder SetCustomData(string customData)
        {
            _aihelpSetLoginUserInfoType.customData = customData;
            return this;
        }

        public AIHelpSetLoginUserInfoTypeBuilder SetTag(string tag)
        {
            _aihelpSetLoginUserInfoType.tag = tag;
            return this;
        }

        public AIHelpSetLoginUserInfoType Build()
        {
            return _aihelpSetLoginUserInfoType;
        }
    }
}