using System;
using ET;
using UnityEngine;
namespace GFGGame
{
    public class AntiAddictionController
    {
        public static void ShowAntiAddictionAlert()
        {
            string promptStr = "您属于未成年人,账号已被纳入防沉迷系统,根据国家新闻出版署《关于防止未成年人沉迷网络游戏的通知》、《关于进一步严格管理切实防止未成年人沉迷网络游戏的通知》要求,您仅可在周五、周六、周日和法定节假日每日20时只21时登录游戏。未满8周岁用户无法充值;8周岁至未满16周岁用户单次充值不得超过50元,每月累计充值金额不得超过200元;16周岁至未满18周岁用户单次充值不得超过100元,每月累计充值金额不得超过400元。目前已超出健康游戏体验时间,将强制游戏下线。";
            AlertSystem.Show(promptStr)
                .SetRightButton(true, "知道啦", (object data) =>
                {
                    GameController.QuitToLoginView(true);
                });
        }
        public static bool CheckAntiAddictionWhenLogin()
        {
            if (!GameGlobal.antiAddiction)
            {
                return false;
            }
            int age = GameGlobal.userAge;
            if (age < 18)
            {
                int remainMinutes = GetRemainGameMinutes();
                if (remainMinutes <= 0)
                {
                    ShowAntiAddictionAlert();
                    return true;
                }
                else
                {
                    string ageRangeStr = null;
                    int maxRechargeSingle = 0;
                    int maxRechargeTotal = 0;
                    GetAntiValue(out ageRangeStr, out maxRechargeSingle, out maxRechargeTotal);
                    string promptStr = "您属于{0}未成年人,已被纳入防沉迷系统。仅可在周五、周六、周日和法定节假日每日20时至21时登录游戏,目前游戏剩余{1}分钟。";
                    promptStr = String.Format(promptStr, ageRangeStr, remainMinutes);
                    if (age < 8)
                    {
                        promptStr += "本游戏不为未满8周岁的用户提供游戏充值服务。";
                    }
                    else
                    {
                        promptStr += "单次充值金额不得超过{0}元人民币,每月充值金额不得超过{1}元人民币。";
                        promptStr = String.Format(promptStr, maxRechargeSingle, maxRechargeTotal);
                    }
                    AlertSystem.Show(promptStr)
                        .SetRightButton(true, "知道啦");
                }
            }
            return false;
        }
        public static bool CheckAntiAddictionWhenPlay()
        {
            if (!GameGlobal.antiAddiction)
            {
                return false;
            }
            int age = GameGlobal.userAge;
            if (age < 18)
            {
                int remainMinutes = GetRemainGameMinutes();
                if (remainMinutes <= 0)
                {
                    string promptStr = "您属于未成年人,已被纳入防沉迷系统。仅可在周五、周六、周日和法定节假日每日20时至21时登录游戏。目前已超出健康游戏体验时间,将强制游戏下线。";
                    AlertSystem.Show(promptStr)
                        .SetRightButton(true, "知道啦", (object data) =>
                        {
                            GameController.QuitToLoginView(false);
                        });
                    return true;
                }
            }
            return false;
        }
        public static bool CheckAntiAddictionRecharge(int value)
        {
            if (!GameGlobal.antiAddiction)
            {
                return false;
            }
            string promptStr = "";
            if (GameGlobal.isVisitor)
            {
                promptStr += "您当前为游客模式,已被纳入防沉迷系统,在此模式下不能充值和付费消费。";
                AlertSystem.Show(promptStr)
                     .SetRightButton(true, "知道啦");
                return true;
            }
            string ageRangeStr = null;
            int maxRechargeSingle = 0;
            int maxRechargeTotal = 0;
            GetAntiValue(out ageRangeStr, out maxRechargeSingle, out maxRechargeTotal);
            promptStr = "您属于{0}未成年人,已被纳入防沉迷系统。";
            promptStr = String.Format(promptStr, ageRangeStr);
            int age = GameGlobal.userAge;
            if (age < 8)
            {
                promptStr += "本游戏不为未满8周岁的用户提供游戏充值服务。";
                AlertSystem.Show(promptStr)
                    .SetRightButton(true, "知道啦");
                return true;
            }
            else if (age < 18)
            {
                int preTotalMon = RoleDataManager.rechargeTotalMon + value;
                if (value > maxRechargeSingle || preTotalMon > maxRechargeTotal)
                {
                    promptStr += "单次充值金额不得超过{0}元人民币,每月充值金额不得超过{1}元人民币。";
                    promptStr = String.Format(promptStr, maxRechargeSingle, maxRechargeTotal);
                    AlertSystem.Show(promptStr)
                        .SetRightButton(true, "知道啦");
                    return true;
                }
            }
            return false;
        }
        private static void GetAntiValue(out string ageRangeStr, out int maxRechargeSingle, out int maxRechargeTotal)
        {
            int age = GameGlobal.userAge;
            if (age < 8)
            {
                ageRangeStr = "未满8周岁";
                maxRechargeSingle = 0;
                maxRechargeTotal = 0;
            }
            else if (age < 16)
            {
                ageRangeStr = "8周岁以上未满16周岁";
                maxRechargeSingle = 50;
                maxRechargeTotal = 200;
            }
            else
            {
                ageRangeStr = "16周岁以上未满18周岁";
                maxRechargeSingle = 100;
                maxRechargeTotal = 400;
            }
        }
        /// 
        /// 防沉迷对象当日剩余可玩时间
        /// 
        /// 
        private static int GetRemainGameMinutes()
        {
            var dateTime = TimeHelper.DateTimeNow();
            int hour = dateTime.Hour;
            if (hour >= 20 && hour < 21)
            {
                int minute = dateTime.Minute;
                return 60 - minute;
            }
            return 0;
        }
    }
}