package com.various.funny.sounds.audio.max;

import android.app.Activity;
import android.util.Log;

import androidx.annotation.NonNull;

import com.applovin.mediation.MaxAd;
import com.applovin.mediation.MaxAdListener;
import com.applovin.mediation.MaxError;
import com.applovin.mediation.ads.MaxInterstitialAd;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MaxManager {

    private static final String id_1 = "d6fa375e3d84dbfc";
    private static final String id_2 = "8f6d9428116466c8";
    private static final String id_3 = "b8c94caf5277e32a";

    public static MaxInterstitialAd checkCacheAd(List<MaxInterstitialAd> list) {
        Collections.shuffle(list);
        for (MaxInterstitialAd ad : list) {
            if (ad.isReady()) {
                return ad;
            }
        }
        return null;
    }

    public static void setMaxListener(MaxInterstitialAd ad, MaxListener maxListener) {
        ad.setListener(new MaxAdListener() {
            @Override
            public void onAdLoaded(@NonNull MaxAd maxAd) {

            }

            @Override
            public void onAdDisplayed(@NonNull MaxAd maxAd) {
                maxListener.onSuccess();
            }

            @Override
            public void onAdHidden(@NonNull MaxAd maxAd) {
                maxListener.onHidden();
            }

            @Override
            public void onAdClicked(@NonNull MaxAd maxAd) {

            }

            @Override
            public void onAdLoadFailed(@NonNull String s, @NonNull MaxError maxError) {

            }

            @Override
            public void onAdDisplayFailed(@NonNull MaxAd maxAd, @NonNull MaxError maxError) {
                maxListener.onFail(maxAd);
            }
        });

    }


    public static List<MaxInterstitialAd> loadAd(Activity activity) {
        MaxInterstitialAd Ad1 = new MaxInterstitialAd(id_1, activity);
        Ad1.loadAd();
        MaxInterstitialAd Ad2 = new MaxInterstitialAd(id_2, activity);
        Ad2.loadAd();
        MaxInterstitialAd Ad3 = new MaxInterstitialAd(id_3, activity);
        Ad3.loadAd();
        ArrayList<MaxInterstitialAd> maxInterstitialAds = new ArrayList<>();
        maxInterstitialAds.add(Ad1);
        maxInterstitialAds.add(Ad2);
        maxInterstitialAds.add(Ad3);
        return maxInterstitialAds;
    }
}
