package coil;

import coil.decode.Decoder;
import coil.fetch.Fetcher;
import coil.fetch.SourceResult;
import coil.intercept.Interceptor;
import coil.key.Keyer;
import coil.map.Mapper;
import coil.request.Options;
import coil.util.Collections;
import java.util.ArrayList;
import java.util.List;
import kotlin.jvm.internal.h;
import kotlin.jvm.internal.o;
import w4.k;
import x4.AbstractC3251q;
import x4.y;

/* JADX INFO: loaded from: classes.dex */
public final class ComponentRegistry {
    private final List<Decoder.Factory> decoderFactories;
    private final List<k> fetcherFactories;
    private final List<Interceptor> interceptors;
    private final List<k> keyers;
    private final List<k> mappers;

    public static final class Builder {
        private final List<Decoder.Factory> decoderFactories;
        private final List<k> fetcherFactories;
        private final List<Interceptor> interceptors;
        private final List<k> keyers;
        private final List<k> mappers;

        public Builder() {
            this.interceptors = new ArrayList();
            this.mappers = new ArrayList();
            this.keyers = new ArrayList();
            this.fetcherFactories = new ArrayList();
            this.decoderFactories = new ArrayList();
        }

        public final Builder add(Interceptor interceptor) {
            this.interceptors.add(interceptor);
            return this;
        }

        public final ComponentRegistry build() {
            return new ComponentRegistry(Collections.toImmutableList(this.interceptors), Collections.toImmutableList(this.mappers), Collections.toImmutableList(this.keyers), Collections.toImmutableList(this.fetcherFactories), Collections.toImmutableList(this.decoderFactories), null);
        }

        public final List<Decoder.Factory> getDecoderFactories$coil_base_release() {
            return this.decoderFactories;
        }

        public final List<k> getFetcherFactories$coil_base_release() {
            return this.fetcherFactories;
        }

        public final List<Interceptor> getInterceptors$coil_base_release() {
            return this.interceptors;
        }

        public final List<k> getKeyers$coil_base_release() {
            return this.keyers;
        }

        public final List<k> getMappers$coil_base_release() {
            return this.mappers;
        }

        public final <T> Builder add(Mapper<T, ?> mapper, Class<T> cls) {
            this.mappers.add(new k(mapper, cls));
            return this;
        }

        public final <T> Builder add(Keyer<T> keyer, Class<T> cls) {
            this.keyers.add(new k(keyer, cls));
            return this;
        }

        public Builder(ComponentRegistry componentRegistry) {
            this.interceptors = AbstractC3251q.E0(componentRegistry.getInterceptors());
            this.mappers = AbstractC3251q.E0(componentRegistry.getMappers());
            this.keyers = AbstractC3251q.E0(componentRegistry.getKeyers());
            this.fetcherFactories = AbstractC3251q.E0(componentRegistry.getFetcherFactories());
            this.decoderFactories = AbstractC3251q.E0(componentRegistry.getDecoderFactories());
        }

        public final <T> Builder add(Fetcher.Factory<T> factory, Class<T> cls) {
            this.fetcherFactories.add(new k(factory, cls));
            return this;
        }

        public final Builder add(Decoder.Factory factory) {
            this.decoderFactories.add(factory);
            return this;
        }

        public final <T> Builder add(Fetcher.Factory<T> factory) {
            o.m();
            throw null;
        }

        public final <T> Builder add(Keyer<T> keyer) {
            o.m();
            throw null;
        }

        public final <T> Builder add(Mapper<T, ?> mapper) {
            o.m();
            throw null;
        }
    }

    public /* synthetic */ ComponentRegistry(List list, List list2, List list3, List list4, List list5, h hVar) {
        this(list, list2, list3, list4, list5);
    }

    public static /* synthetic */ k newDecoder$default(ComponentRegistry componentRegistry, SourceResult sourceResult, Options options, ImageLoader imageLoader, int i6, int i7, Object obj) {
        if ((i7 & 8) != 0) {
            i6 = 0;
        }
        return componentRegistry.newDecoder(sourceResult, options, imageLoader, i6);
    }

    public static /* synthetic */ k newFetcher$default(ComponentRegistry componentRegistry, Object obj, Options options, ImageLoader imageLoader, int i6, int i7, Object obj2) {
        if ((i7 & 8) != 0) {
            i6 = 0;
        }
        return componentRegistry.newFetcher(obj, options, imageLoader, i6);
    }

    public final List<Decoder.Factory> getDecoderFactories() {
        return this.decoderFactories;
    }

    public final List<k> getFetcherFactories() {
        return this.fetcherFactories;
    }

    public final List<Interceptor> getInterceptors() {
        return this.interceptors;
    }

    public final List<k> getKeyers() {
        return this.keyers;
    }

    public final List<k> getMappers() {
        return this.mappers;
    }

    public final String key(Object obj, Options options) {
        List<k> list = this.keyers;
        int size = list.size();
        for (int i6 = 0; i6 < size; i6++) {
            k kVar = list.get(i6);
            Keyer keyer = (Keyer) kVar.f25469a;
            if (((Class) kVar.f25470b).isAssignableFrom(obj.getClass())) {
                o.f(keyer, "null cannot be cast to non-null type coil.key.Keyer<kotlin.Any>");
                String strKey = keyer.key(obj, options);
                if (strKey != null) {
                    return strKey;
                }
            }
        }
        return null;
    }

    public final Object map(Object obj, Options options) {
        List<k> list = this.mappers;
        int size = list.size();
        for (int i6 = 0; i6 < size; i6++) {
            k kVar = list.get(i6);
            Mapper mapper = (Mapper) kVar.f25469a;
            if (((Class) kVar.f25470b).isAssignableFrom(obj.getClass())) {
                o.f(mapper, "null cannot be cast to non-null type coil.map.Mapper<kotlin.Any, *>");
                Object map = mapper.map(obj, options);
                if (map != null) {
                    obj = map;
                }
            }
        }
        return obj;
    }

    public final Builder newBuilder() {
        return new Builder(this);
    }

    public final k newDecoder(SourceResult sourceResult, Options options, ImageLoader imageLoader) {
        return newDecoder$default(this, sourceResult, options, imageLoader, 0, 8, null);
    }

    public final k newFetcher(Object obj, Options options, ImageLoader imageLoader) {
        return newFetcher$default(this, obj, options, imageLoader, 0, 8, null);
    }

    /* JADX WARN: Multi-variable type inference failed */
    private ComponentRegistry(List<? extends Interceptor> list, List<? extends k> list2, List<? extends k> list3, List<? extends k> list4, List<? extends Decoder.Factory> list5) {
        this.interceptors = list;
        this.mappers = list2;
        this.keyers = list3;
        this.fetcherFactories = list4;
        this.decoderFactories = list5;
    }

    public final k newDecoder(SourceResult sourceResult, Options options, ImageLoader imageLoader, int i6) {
        int size = this.decoderFactories.size();
        while (i6 < size) {
            Decoder decoderCreate = this.decoderFactories.get(i6).create(sourceResult, options, imageLoader);
            if (decoderCreate != null) {
                return new k(decoderCreate, Integer.valueOf(i6));
            }
            i6++;
        }
        return null;
    }

    public final k newFetcher(Object obj, Options options, ImageLoader imageLoader, int i6) {
        int size = this.fetcherFactories.size();
        while (i6 < size) {
            k kVar = this.fetcherFactories.get(i6);
            Fetcher.Factory factory = (Fetcher.Factory) kVar.f25469a;
            if (((Class) kVar.f25470b).isAssignableFrom(obj.getClass())) {
                o.f(factory, "null cannot be cast to non-null type coil.fetch.Fetcher.Factory<kotlin.Any>");
                Fetcher fetcherCreate = factory.create(obj, options, imageLoader);
                if (fetcherCreate != null) {
                    return new k(fetcherCreate, Integer.valueOf(i6));
                }
            }
            i6++;
        }
        return null;
    }

    /* JADX WARN: Illegal instructions before constructor call */
    public ComponentRegistry() {
        y yVar = y.f26065a;
        this(yVar, yVar, yVar, yVar, yVar);
    }
}
