
namespace Guru
{
    using UnityEngine;

    /// <summary>
    /// MAX 自有渠道初始化
    /// </summary>
    public class AdChanelMax: IAdChannel
    {
        #region 属性

        public static readonly string ChanelName = "AppLovinMax";
        public string Name => ChanelName;

        public bool IsEnabled => true;

        #endregion
        
        #region 广告位
        
        // ---------------- Max 广告位ID -------------------- 
        private string MaxBannerSlotID => GuruSettings.Instance.ADSetting.GetBannerID();
        private string MaxIVSlotID => GuruSettings.Instance.ADSetting.GetInterstitialID();
        private string MaxRVSlotID => GuruSettings.Instance.ADSetting.GetRewardedVideoID();
        
        #endregion
        
        #region 初始化
        
        /// <summary>
        /// MAX 渠道初始化, 启动服务
        /// </summary>
        public void Initialize()
        {
            MaxSdk.SetMuted(false);
            MaxSdk.SetSdkKey(GuruSettings.Instance.ADSetting.SDK_KEY);
            MaxSdk.SetUserId(IPMConfig.IPM_UID);  // 上报用户ID
            MaxSdk.InitializeSdk();
        }

        #endregion
        
        #region Banner

        private Color _backColor = Color.clear;
        public bool IsBannerRequestOver => true;
        public void LoadBannerAD()
        {
            // Banners are automatically sized to 320x50 on phones and 728x90 on tablets
            // You may use the utility method `MaxSdkUtils.isTablet()` to help with view sizing adjustments
            MaxSdk.CreateBanner(MaxBannerSlotID, MaxSdkBase.BannerPosition.BottomCenter);
            MaxSdk.SetBannerExtraParameter(MaxBannerSlotID, "adaptive_banner", "false");
            // Set background or background color for banners to be fully functional
            MaxSdk.SetBannerBackgroundColor(MaxBannerSlotID, _backColor);
            Analytics.ADBadsLoad(AdParams.Build(MaxBannerSlotID));
        }
        
        #endregion
        
        #region Interstitial
        
        public bool IsInterstitialRequestOver => true;
        public void LoadInterstitialAD()
        {
            Analytics.ADIadsLoad(AdParams.Build(MaxIVSlotID)); // 上报打点
            MaxSdk.LoadInterstitial(MaxIVSlotID);
        }

        #endregion
        
        #region Reward

        public bool IsRewardRequestOver => true;
        public void LoadRewardAD()
        {
            Analytics.ADRadsLoad(AdParams.Build(MaxRVSlotID)); // 上报打点
            MaxSdk.LoadRewardedAd(MaxRVSlotID);
        }

        #endregion
       
    }
}