package com.vungle.mediation;

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.annotation.Size;

import com.vungle.warren.AdConfig;

/**
 * A helper class for creating a network extras bundle that can be passed to the adapter to make
 * customizations specific to Vungle.
 */
public final class VungleExtrasBuilder {

    public static final String EXTRA_USER_ID = "userId";
    private static final String EXTRA_SOUND_ENABLED = "soundEnabled";
    private static final String EXTRA_FLEXVIEW_CLOSE_TIME = "flexViewCloseTimeInSec";
    private static final String EXTRA_ORDINAL_VIEW_COUNT = "ordinalViewCount";
    private static final String EXTRA_ORIENTATION = "adOrientation";
    static final String EXTRA_ALL_PLACEMENTS = "allPlacements";
    static final String EXTRA_PLAY_PLACEMENT = "playPlacement";

    private final Bundle mBundle = new Bundle();

    public VungleExtrasBuilder(@Nullable @Size(min = 1L) String[] placements) {
        mBundle.putStringArray(EXTRA_ALL_PLACEMENTS, placements);
    }

    public VungleExtrasBuilder setPlayingPlacement(String placement) {
        mBundle.putString(EXTRA_PLAY_PLACEMENT, placement);
        return this;
    }

    public VungleExtrasBuilder setSoundEnabled(boolean enabled) {
        mBundle.putBoolean(EXTRA_SOUND_ENABLED, enabled);
        return this;
    }

    public VungleExtrasBuilder setUserId(String userId) {
        mBundle.putString(EXTRA_USER_ID, userId);
        return this;
    }

    public VungleExtrasBuilder setFlexViewCloseTimeInSec(int flexViewCloseTimeInSec) {
        mBundle.putInt(EXTRA_FLEXVIEW_CLOSE_TIME, flexViewCloseTimeInSec);
        return this;
    }

    public VungleExtrasBuilder setOrdinalViewCount(int ordinalViewCount) {
        mBundle.putInt(EXTRA_ORDINAL_VIEW_COUNT, ordinalViewCount);
        return this;
    }

    public VungleExtrasBuilder setAdOrientation(int adOrientation) {
        mBundle.putInt(EXTRA_ORIENTATION, adOrientation);
        return this;
    }

    public Bundle build() {
        return mBundle;
    }

    public static AdConfig adConfigWithNetworkExtras(Bundle networkExtras) {
        AdConfig adConfig = new AdConfig();
        if (networkExtras != null) {
            adConfig.setMuted(!networkExtras.getBoolean(EXTRA_SOUND_ENABLED, true));
            adConfig.setFlexViewCloseTime(networkExtras.getInt(EXTRA_FLEXVIEW_CLOSE_TIME, 0));
            adConfig.setOrdinal(networkExtras.getInt(EXTRA_ORDINAL_VIEW_COUNT, 0));
            adConfig.setAdOrientation(networkExtras.getInt(EXTRA_ORIENTATION, AdConfig.AUTO_ROTATE));
        }
        return adConfig;
    }

    public static boolean isStartMuteConfigured(Bundle networkExtras) {
        return networkExtras.containsKey(EXTRA_SOUND_ENABLED);
    }
}

@@ -442,34 +442,30 @@
 RA_S
-OUND_ENABLED = %22soundEnabl
+TART_MUTED = %22startMut
 ed%22;
@@ -1182,32 +1182,48 @@
 rn this;%0A    %7D%0A%0A
+    @Deprecated%0A
     public Vungl
@@ -1268,24 +1268,133 @@
  enabled) %7B%0A
+        return setStartMuted(!enabled);%0A    %7D%0A%0A    public VungleExtrasBuilder setStartMuted(boolean muted) %7B%0A
         mBun
@@ -1419,27 +1419,23 @@
 RA_S
-OUND_ENABLED, enabl
+TART_MUTED, mut
 ed);
@@ -2362,17 +2362,16 @@
 etMuted(
-!
 networkE
@@ -2398,25 +2398,24 @@
 RA_S
-OUND_ENABLED, tru
+TART_MUTED, fals
 e));
@@ -2738,31 +2738,24 @@
 %0A    %7D%0A%0A    
-public 
 static boole
@@ -2768,16 +2768,20 @@
 tartMute
+dNot
 Configur
@@ -2822,16 +2822,17 @@
  return 
+!
 networkE
@@ -2860,18 +2860,16 @@
 RA_S
-OUND_ENABL
+TART_MUT
 ED);

Rename from EXTRA_SOUND_ENABLED to EXTRA_START_MUTED