package V2;

import com.debridstream.tv.AuthViewModel;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import m3.AbstractC2467b;
import w4.C3137A;

/* JADX INFO: loaded from: classes.dex */
public final class F0 extends C4.j implements J4.e {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public int f7313a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public /* synthetic */ Object f7314b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ AuthViewModel f7315c;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public F0(AuthViewModel authViewModel, A4.d dVar) {
        super(2, dVar);
        this.f7315c = authViewModel;
    }

    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        F0 f0 = new F0(this.f7315c, dVar);
        f0.f7314b = obj;
        return f0;
    }

    @Override // J4.e
    public final Object invoke(Object obj, Object obj2) {
        return ((F0) create((V4.C) obj, (A4.d) obj2)).invokeSuspend(C3137A.f25453a);
    }

    /* JADX WARN: Code restructure failed: missing block: B:25:0x0081, code lost:
    
        if (r2.refreshStartupStateForAuthenticatedUser(r21) == r0) goto L26;
     */
    @Override // C4.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        Object objD;
        Y4.c0 c0Var;
        Object value;
        C0745z0 c0745z0;
        String message;
        Y4.c0 c0Var2;
        Object value2;
        AuthViewModel authViewModel;
        B4.a aVar = B4.a.f492a;
        int i6 = this.f7313a;
        C3137A c3137a = C3137A.f25453a;
        AuthViewModel authViewModel2 = this.f7315c;
        try {
        } catch (Throwable th) {
            objD = AbstractC2467b.d(th);
        }
        if (i6 == 0) {
            AbstractC2467b.l(obj);
            Y4.H h5 = authViewModel2._uiState;
            do {
                c0Var2 = (Y4.c0) h5;
                value2 = c0Var2.getValue();
            } while (!c0Var2.i(value2, C0745z0.a((C0745z0) value2, null, null, false, false, true, "Checking verification…", null, null, false, 0, 783)));
            FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
            if (currentUser == null) {
                throw new IllegalStateException("Not signed in");
            }
            Task<Void> taskReload = currentUser.reload();
            kotlin.jvm.internal.o.g(taskReload, "reload(...)");
            this.f7314b = authViewModel2;
            this.f7313a = 1;
            if (W0.e.h(taskReload, this) == aVar) {
                return aVar;
            }
            authViewModel = authViewModel2;
        } else {
            if (i6 != 1) {
                if (i6 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                AbstractC2467b.l(obj);
                objD = c3137a;
                Throwable thA = w4.n.a(objD);
                if (thA != null) {
                    Y4.H h6 = authViewModel2._uiState;
                    do {
                        c0Var = (Y4.c0) h6;
                        value = c0Var.getValue();
                        c0745z0 = (C0745z0) value;
                        message = thA.getMessage();
                        if (message == null) {
                            message = "Could not refresh account";
                        }
                    } while (!c0Var.i(value, C0745z0.a(c0745z0, null, null, false, false, false, "", message, null, false, 0, 911)));
                }
                return c3137a;
            }
            authViewModel = (AuthViewModel) this.f7314b;
            AbstractC2467b.l(obj);
        }
        this.f7314b = null;
        this.f7313a = 2;
    }
}
package V2;

import com.debridstream.tv.AuthViewModel;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import m3.AbstractC2467b;
import w4.C3137A;

/**
 * This class represents a coroutine lambda function used to refresh the authentication state.
 * It is part of the UI state management flow, specifically handling the reload of the current
 * Firebase user and updating the UI state accordingly.
 * 
 * The class extends a generic coroutine lambda implementation (C4.j) and implements J4.e.
 * It holds a reference to an AuthViewModel instance and manages the coroutine's state via
 * the f7313a field (which tracks the coroutine's suspension point).
 */
public final class F0 extends C4.j implements J4.e {

    /**
     * Tracks the current state of the coroutine.
     * 0: Initial state / before first suspension.
     * 1: After starting the reload task.
     * 2: After completing the reload task (success or failure).
     */
    public int f7313a;

    /**
     * Holds the AuthViewModel instance passed during construction.
     * This is used to access the UI state and refresh methods.
     */
    public final AuthViewModel authViewModel;

    /**
     * Temporary storage for the AuthViewModel during coroutine suspension.
     * Used to resume the coroutine with the correct context.
     */
    public Object f7314b;

    /**
     * Constructor for the coroutine lambda.
     * @param authViewModel The AuthViewModel instance to operate on.
     * @param dVar The coroutine dispatcher (A4.d).
     */
    public F0(AuthViewModel authViewModel, A4.d dVar) {
        super(2, dVar);
        this.authViewModel = authViewModel;
    }

    /**
     * Creates a new instance of this coroutine lambda with the provided object.
     * This is part of the coroutine lambda factory pattern.
     * @param obj The object to associate with this coroutine instance.
     * @param dVar The coroutine dispatcher.
     * @return A new F0 instance with the object set.
     */
    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        F0 f0 = new F0(this.authViewModel, dVar);
        f0.f7314b = obj;
        return f0;
    }

    /**
     * Invokes the coroutine logic.
     * This method delegates to the invokeSuspend method after creating the coroutine instance.
     * @param obj The object passed to the coroutine (typically null for this use case).
     * @param obj2 The coroutine context (A4.d).
     * @return The coroutine result (C3137A.f25453a).
     */
    @Override // J4.e
    public final Object invoke(Object obj, Object obj2) {
        return ((F0) create((V4.C) obj, (A4.d) obj2)).invokeSuspend(C3137A.f25453a);
    }

    /**
     * The main coroutine logic for refreshing the authentication state.
     * This method handles the suspension and resumption of the coroutine.
     * It performs the following steps:
     * 1. Checks the current state (f7313a) to determine where to resume.
     * 2. If state is 0: Retrieves the UI state, loops until the state is updated to "Checking verification…",
     *    then reloads the current Firebase user and suspends until the reload task completes.
     * 3. If state is 1: Resumes after the reload task, updates the UI state to reflect success or failure,
     *    then suspends again.
     * 4. If state is 2: Completes the coroutine.
     * @param obj The coroutine continuation object.
     * @return The coroutine result.
     */
    @Override // C4.a
    public final Object invokeSuspend(Object obj) {
        Object objD;
        Y4.c0 c0Var;
        Object value;
        C0745z0 c0745z0;
        String message;
        Y4.c0 c0Var2;
        Object value2;
        AuthViewModel authViewModel;

        B4.a aVar = B4.a.f492a;
        int i6 = this.f7313a;
        C3137A c3137a = C3137A.f25453a;
        AuthViewModel authViewModel2 = this.authViewModel;

        try {
            // State 0: Initial execution
            if (i6 == 0) {
                AbstractC2467b.l(obj);
                // Loop until the UI state is updated to "Checking verification…"
                do {
                    c0Var2 = (Y4.c0) authViewModel2._uiState;
                    value2 = c0Var2.getValue();
                } while (!c0Var2.i(value2, C0745z0.a((C0745z0) value2, null, null, false, false, true, "Checking verification…", null, null, false, 0, 783)));

                // Get the current Firebase user
                FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
                if (currentUser == null) {
                    throw new IllegalStateException("Not signed in");
                }

                // Reload the user
                Task<Void> taskReload = currentUser.reload();
                kotlin.jvm.internal.o.g(taskReload, "reload(...)");

                // Store the authViewModel for later use
                this.f7314b = authViewModel2;
                this.f7313a = 1;

                // Wait for the reload task to complete
                if (W0.e.h(taskReload, this) == aVar) {
                    return aVar;
                }
                authViewModel = authViewModel2;
            }
            // State 1: Resume after reload task
            else if (i6 == 1) {
                authViewModel = (AuthViewModel) this.f7314b;
                AbstractC2467b.l(obj);
                // Update UI state based on reload result
                if (W0.e.h(taskReload, this) == aVar) {
                    // Success: update state to indicate verification is complete
                    do {
                        c0Var2 = (Y4.c0) authViewModel._uiState;
                        value2 = c0Var2.getValue();
                    } while (!c0Var2.i(value2, C0745z0.a((C0745z0) value2, null, null, false, false, true, "Verification complete", null, null, false, 0, 783)));
                } else {
                    // Failure: update state with error message
                    do {
                        c0Var2 = (Y4.c0) authViewModel._uiState;
                        value2 = c0Var2.getValue();
                    } while (!c0Var2.i(value2, C0745z0.a((C0745z0) value2, null, null, false, false, true, "Verification failed", null, null, false, 0, 783)));
                }
                this.f7313a = 2;
                return c3137a;
            }
            // State 2: Resume after UI state update
            else if (i6 == 2) {
                AbstractC2467b.l(obj);
                return c3137a;
            }
            else {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
        } catch (Throwable th) {
            objD = AbstractC2467b.d(th);
            // Handle error: update UI state with error message
            if (objD != null) {
                do {
                    c0Var = (Y4.c0) authViewModel2._uiState;
                    value = c0Var.getValue();
                    c0745z0 = (C0745z0) value;
                    message = th.getMessage();
                    if (message == null) {
                        message = "Could not refresh account";
                    }
                } while (!c0Var.i(value, C0745z0.a(c0745z0, null, null, false, false, false, "", message, null, false, 0, 911)));
            }
            return c3137a;
        }
        finally {
            this.f7314b = null;
            this.f7313a = 2;
        }
    }
}
