package m4;

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

/* JADX INFO: loaded from: classes3.dex */
public final class M1 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final boolean f20681a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final List f20682b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Collection f20683c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Collection f20684d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final int f20685e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final P1 f20686f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final boolean f20687g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final boolean f20688h;

    public M1(List list, Collection collection, Collection collection2, P1 p12, boolean z6, boolean z7, boolean z8, int i6) {
        this.f20682b = list;
        A4.g.o(collection, "drainedSubstreams");
        this.f20683c = collection;
        this.f20686f = p12;
        this.f20684d = collection2;
        this.f20687g = z6;
        this.f20681a = z7;
        this.f20688h = z8;
        this.f20685e = i6;
        A4.g.t(!z7 || list == null, "passThrough should imply buffer is null");
        A4.g.t((z7 && p12 == null) ? false : true, "passThrough should imply winningSubstream != null");
        A4.g.t(!z7 || (collection.size() == 1 && collection.contains(p12)) || (collection.size() == 0 && p12.f20723b), "passThrough should imply winningSubstream is drained");
        A4.g.t((z6 && p12 == null) ? false : true, "cancelled should imply committed");
    }

    public final M1 a(P1 p12) {
        Collection collectionUnmodifiableCollection;
        A4.g.t(!this.f20688h, "hedging frozen");
        A4.g.t(this.f20686f == null, "already committed");
        Collection collection = this.f20684d;
        if (collection == null) {
            collectionUnmodifiableCollection = Collections.singleton(p12);
        } else {
            ArrayList arrayList = new ArrayList(collection);
            arrayList.add(p12);
            collectionUnmodifiableCollection = Collections.unmodifiableCollection(arrayList);
        }
        return new M1(this.f20682b, this.f20683c, collectionUnmodifiableCollection, this.f20686f, this.f20687g, this.f20681a, this.f20688h, this.f20685e + 1);
    }

    public final M1 b(P1 p12) {
        ArrayList arrayList = new ArrayList(this.f20684d);
        arrayList.remove(p12);
        return new M1(this.f20682b, this.f20683c, Collections.unmodifiableCollection(arrayList), this.f20686f, this.f20687g, this.f20681a, this.f20688h, this.f20685e);
    }

    public final M1 c(P1 p12, P1 p13) {
        ArrayList arrayList = new ArrayList(this.f20684d);
        arrayList.remove(p12);
        arrayList.add(p13);
        return new M1(this.f20682b, this.f20683c, Collections.unmodifiableCollection(arrayList), this.f20686f, this.f20687g, this.f20681a, this.f20688h, this.f20685e);
    }

    public final M1 d(P1 p12) {
        p12.f20723b = true;
        Collection collection = this.f20683c;
        if (!collection.contains(p12)) {
            return this;
        }
        ArrayList arrayList = new ArrayList(collection);
        arrayList.remove(p12);
        return new M1(this.f20682b, Collections.unmodifiableCollection(arrayList), this.f20684d, this.f20686f, this.f20687g, this.f20681a, this.f20688h, this.f20685e);
    }

    public final M1 e(P1 p12) {
        List list;
        A4.g.t(!this.f20681a, "Already passThrough");
        boolean z6 = p12.f20723b;
        Collection collectionUnmodifiableCollection = this.f20683c;
        if (!z6) {
            if (collectionUnmodifiableCollection.isEmpty()) {
                collectionUnmodifiableCollection = Collections.singletonList(p12);
            } else {
                ArrayList arrayList = new ArrayList(collectionUnmodifiableCollection);
                arrayList.add(p12);
                collectionUnmodifiableCollection = Collections.unmodifiableCollection(arrayList);
            }
        }
        Collection collection = collectionUnmodifiableCollection;
        P1 p13 = this.f20686f;
        boolean z7 = p13 != null;
        if (z7) {
            A4.g.t(p13 == p12, "Another RPC attempt has already committed");
            list = null;
        } else {
            list = this.f20682b;
        }
        return new M1(list, collection, this.f20684d, this.f20686f, this.f20687g, z7, this.f20688h, this.f20685e);
    }
}
