package com.strmr.ps.data.repository;

import androidx.media3.container.NalUnitUtil;
import androidx.media3.extractor.AacUtil;
import androidx.media3.extractor.text.ttml.TtmlNode;
import com.strmr.ps.data.local.dao.CachedContentDao;
import com.strmr.ps.data.local.entity.CachedContent;
import com.strmr.ps.data.model.ContentItem;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.kp6;
import defpackage.m02;
import defpackage.m12;
import defpackage.n89;
import defpackage.pq6;
import defpackage.s38;
import defpackage.sc2;
import defpackage.vx8;
import defpackage.wj0;
import defpackage.y41;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Singleton;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;

/* JADX INFO: loaded from: classes3.dex */
@Singleton
@Metadata(d1 = {"\u0000@\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\t\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\f\b\u0007\u0018\u0000 !2\u00020\u0001:\u0001!B\u0011\b\u0007\u0012\u0006\u0010\u0003\u001a\u00020\u0002¢\u0006\u0004\b\u0004\u0010\u0005J\u0017\u0010\t\u001a\u00020\b2\u0006\u0010\u0007\u001a\u00020\u0006H\u0002¢\u0006\u0004\b\t\u0010\nJ\u0018\u0010\f\u001a\u00020\u000b2\u0006\u0010\u0007\u001a\u00020\u0006H\u0086@¢\u0006\u0004\b\f\u0010\rJ\u0010\u0010\u000f\u001a\u00020\u000eH\u0086@¢\u0006\u0004\b\u000f\u0010\u0010J\u0018\u0010\u0011\u001a\u00020\u000e2\u0006\u0010\u0007\u001a\u00020\u0006H\u0086@¢\u0006\u0004\b\u0011\u0010\rJ\u001a\u0010\u0012\u001a\u0004\u0018\u00010\b2\u0006\u0010\u0007\u001a\u00020\u0006H\u0086@¢\u0006\u0004\b\u0012\u0010\rJ \u0010\u0015\u001a\n\u0012\u0004\u0012\u00020\u0014\u0018\u00010\u00132\u0006\u0010\u0007\u001a\u00020\u0006H\u0086@¢\u0006\u0004\b\u0015\u0010\rJ.\u0010\u0019\u001a\b\u0012\u0004\u0012\u00020\u00140\u00132\u0006\u0010\u0007\u001a\u00020\u00062\u0006\u0010\u0017\u001a\u00020\u00162\u0006\u0010\u0018\u001a\u00020\u0016H\u0086@¢\u0006\u0004\b\u0019\u0010\u001aJ6\u0010\u001c\u001a\u00020\u000e2\u0006\u0010\u0007\u001a\u00020\u00062\f\u0010\u001b\u001a\b\u0012\u0004\u0012\u00020\u00140\u00132\u0006\u0010\u0017\u001a\u00020\u00162\u0006\u0010\u0018\u001a\u00020\u0016H\u0086@¢\u0006\u0004\b\u001c\u0010\u001dJ&\u0010\u001e\u001a\u00020\u000e2\u0006\u0010\u0007\u001a\u00020\u00062\f\u0010\u001b\u001a\b\u0012\u0004\u0012\u00020\u00140\u0013H\u0086@¢\u0006\u0004\b\u001e\u0010\u001fR\u0014\u0010\u0003\u001a\u00020\u00028\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0003\u0010 ¨\u0006\""}, d2 = {"Lcom/strmr/ps/data/repository/CacheRepository;", "", "Lcom/strmr/ps/data/local/dao/CachedContentDao;", "cachedContentDao", "<init>", "(Lcom/strmr/ps/data/local/dao/CachedContentDao;)V", "", "category", "", "getTTLForCategory", "(Ljava/lang/String;)J", "", "isCacheFresh", "(Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "Le6a;", "cleanupOldCache", "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "clearCategoryCache", "getCacheAge", "", "Lcom/strmr/ps/data/model/ContentItem;", "getCachedContent", "", "page", "pageSize", "getCachedPage", "(Ljava/lang/String;IILkotlin/coroutines/Continuation;)Ljava/lang/Object;", "content", "cacheContentPage", "(Ljava/lang/String;Ljava/util/List;IILkotlin/coroutines/Continuation;)Ljava/lang/Object;", "cacheContent", "(Ljava/lang/String;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "Lcom/strmr/ps/data/local/dao/CachedContentDao;", "Companion", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
public final class CacheRepository {
    private static final long DETAILS_TTL;
    private static final long LIST_TTL;
    private static final long MAX_CACHE_AGE;
    private static final long TRAKT_LIST_TTL;

    @kp6
    private final CachedContentDao cachedContentDao;

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.CacheRepository$cacheContent$2, reason: invalid class name */
    @Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "Le6a;", "<anonymous>", "(Lak1;)V"}, k = 3, mv = {2, 0, 0})
    @DebugMetadata(c = "com.strmr.ps.data.repository.CacheRepository$cacheContent$2", f = "CacheRepository.kt", i = {}, l = {117}, m = "invokeSuspend", n = {}, s = {})
    @vx8
    public static final class AnonymousClass2 extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
        final /* synthetic */ String $category;
        final /* synthetic */ List<ContentItem> $content;
        int label;
        final /* synthetic */ CacheRepository this$0;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public AnonymousClass2(List<ContentItem> list, CacheRepository cacheRepository, String str, Continuation<? super AnonymousClass2> continuation) {
            super(2, continuation);
            this.$content = list;
            this.this$0 = cacheRepository;
            this.$category = str;
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            return new AnonymousClass2(this.$content, this.this$0, this.$category, continuation);
        }

        @Override // defpackage.gr3
        public final Object invoke(ak1 ak1Var, Continuation<? super e6a> continuation) {
            return ((AnonymousClass2) create(ak1Var, continuation)).invokeSuspend(e6a.a);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) {
            ck1 ck1Var = ck1.a;
            int i = this.label;
            if (i == 0) {
                s38.b(obj);
                List<ContentItem> list = this.$content;
                String str = this.$category;
                ArrayList arrayList = new ArrayList(y41.p(list, 10));
                int i2 = 0;
                for (Object obj2 : list) {
                    int i3 = i2 + 1;
                    if (i2 < 0) {
                        y41.bm();
                        throw null;
                    }
                    arrayList.add(CachedContent.INSTANCE.fromContentItem((ContentItem) obj2, str, i2));
                    i2 = i3;
                }
                CachedContentDao cachedContentDao = this.this$0.cachedContentDao;
                String str2 = this.$category;
                this.label = 1;
                if (cachedContentDao.replaceCategoryContent(str2, arrayList, this) == ck1Var) {
                    return ck1Var;
                }
            } else {
                if (i != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(obj);
            }
            return e6a.a;
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.CacheRepository$cacheContentPage$2, reason: invalid class name and case insensitive filesystem */
    @Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "Le6a;", "<anonymous>", "(Lak1;)V"}, k = 3, mv = {2, 0, 0})
    @DebugMetadata(c = "com.strmr.ps.data.repository.CacheRepository$cacheContentPage$2", f = "CacheRepository.kt", i = {0}, l = {98, 107}, m = "invokeSuspend", n = {TtmlNode.START}, s = {"I$0"})
    @vx8
    public static final class C02842 extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
        final /* synthetic */ String $category;
        final /* synthetic */ List<ContentItem> $content;
        final /* synthetic */ int $page;
        final /* synthetic */ int $pageSize;
        int I$0;
        int label;
        final /* synthetic */ CacheRepository this$0;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C02842(List<ContentItem> list, int i, int i2, CacheRepository cacheRepository, String str, Continuation<? super C02842> continuation) {
            super(2, continuation);
            this.$content = list;
            this.$page = i;
            this.$pageSize = i2;
            this.this$0 = cacheRepository;
            this.$category = str;
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            return new C02842(this.$content, this.$page, this.$pageSize, this.this$0, this.$category, continuation);
        }

        @Override // defpackage.gr3
        public final Object invoke(ak1 ak1Var, Continuation<? super e6a> continuation) {
            return ((C02842) create(ak1Var, continuation)).invokeSuspend(e6a.a);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) {
            int i;
            ck1 ck1Var = ck1.a;
            int i2 = this.label;
            e6a e6aVar = e6a.a;
            if (i2 == 0) {
                s38.b(obj);
                if (this.$content.isEmpty()) {
                    return e6aVar;
                }
                i = this.$pageSize * (this.$page - 1);
                int size = (this.$content.size() + i) - 1;
                CachedContentDao cachedContentDao = this.this$0.cachedContentDao;
                String str = this.$category;
                this.I$0 = i;
                this.label = 1;
                if (cachedContentDao.deleteRange(str, i, size, this) != ck1Var) {
                }
            }
            if (i2 != 1) {
                if (i2 == 2) {
                    s38.b(obj);
                }
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            i = this.I$0;
            s38.b(obj);
            List<ContentItem> list = this.$content;
            String str2 = this.$category;
            ArrayList arrayList = new ArrayList(y41.p(list, 10));
            int i3 = 0;
            for (Object obj2 : list) {
                int i4 = i3 + 1;
                if (i3 < 0) {
                    y41.bm();
                    throw null;
                }
                arrayList.add(CachedContent.INSTANCE.fromContentItem((ContentItem) obj2, str2, i3 + i));
                i3 = i4;
            }
            CachedContentDao cachedContentDao2 = this.this$0.cachedContentDao;
            this.label = 2;
            return cachedContentDao2.insertContent(arrayList, this) == ck1Var ? ck1Var : e6aVar;
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.CacheRepository$cleanupOldCache$2, reason: invalid class name and case insensitive filesystem */
    @Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "Le6a;", "<anonymous>", "(Lak1;)V"}, k = 3, mv = {2, 0, 0})
    @DebugMetadata(c = "com.strmr.ps.data.repository.CacheRepository$cleanupOldCache$2", f = "CacheRepository.kt", i = {}, l = {AacUtil.AUDIO_OBJECT_TYPE_AAC_XHE}, m = "invokeSuspend", n = {}, s = {})
    public static final class C02852 extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
        int label;

        public C02852(Continuation<? super C02852> continuation) {
            super(2, continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            return CacheRepository.this.new C02852(continuation);
        }

        @Override // defpackage.gr3
        public final Object invoke(ak1 ak1Var, Continuation<? super e6a> continuation) {
            return ((C02852) create(ak1Var, continuation)).invokeSuspend(e6a.a);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) {
            ck1 ck1Var = ck1.a;
            int i = this.label;
            if (i == 0) {
                s38.b(obj);
                long jCurrentTimeMillis = System.currentTimeMillis() - CacheRepository.MAX_CACHE_AGE;
                CachedContentDao cachedContentDao = CacheRepository.this.cachedContentDao;
                this.label = 1;
                if (cachedContentDao.deleteOldContent(jCurrentTimeMillis, this) == ck1Var) {
                    return ck1Var;
                }
            } else {
                if (i != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(obj);
            }
            return e6a.a;
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.CacheRepository$clearCategoryCache$2, reason: invalid class name and case insensitive filesystem */
    @Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "Le6a;", "<anonymous>", "(Lak1;)V"}, k = 3, mv = {2, 0, 0})
    @DebugMetadata(c = "com.strmr.ps.data.repository.CacheRepository$clearCategoryCache$2", f = "CacheRepository.kt", i = {}, l = {49}, m = "invokeSuspend", n = {}, s = {})
    public static final class C02862 extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
        final /* synthetic */ String $category;
        int label;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C02862(String str, Continuation<? super C02862> continuation) {
            super(2, continuation);
            this.$category = str;
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            return CacheRepository.this.new C02862(this.$category, continuation);
        }

        @Override // defpackage.gr3
        public final Object invoke(ak1 ak1Var, Continuation<? super e6a> continuation) {
            return ((C02862) create(ak1Var, continuation)).invokeSuspend(e6a.a);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) {
            ck1 ck1Var = ck1.a;
            int i = this.label;
            if (i == 0) {
                s38.b(obj);
                CachedContentDao cachedContentDao = CacheRepository.this.cachedContentDao;
                String str = this.$category;
                this.label = 1;
                if (cachedContentDao.deleteCategoryContent(str, this) == ck1Var) {
                    return ck1Var;
                }
            } else {
                if (i != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(obj);
            }
            return e6a.a;
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.CacheRepository$getCacheAge$2, reason: invalid class name and case insensitive filesystem */
    @Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0010\t\n\u0002\b\u0002\u0010\u0002\u001a\u0004\u0018\u00010\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "", "<anonymous>", "(Lak1;)J"}, k = 3, mv = {2, 0, 0})
    @DebugMetadata(c = "com.strmr.ps.data.repository.CacheRepository$getCacheAge$2", f = "CacheRepository.kt", i = {}, l = {68}, m = "invokeSuspend", n = {}, s = {})
    @vx8
    public static final class C02872 extends SuspendLambda implements gr3<ak1, Continuation<? super Long>, Object> {
        final /* synthetic */ String $category;
        int label;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C02872(String str, Continuation<? super C02872> continuation) {
            super(2, continuation);
            this.$category = str;
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            return CacheRepository.this.new C02872(this.$category, continuation);
        }

        @Override // defpackage.gr3
        public final Object invoke(ak1 ak1Var, Continuation<? super Long> continuation) {
            return ((C02872) create(ak1Var, continuation)).invokeSuspend(e6a.a);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) {
            ck1 ck1Var = ck1.a;
            int i = this.label;
            if (i == 0) {
                s38.b(obj);
                CachedContentDao cachedContentDao = CacheRepository.this.cachedContentDao;
                String str = this.$category;
                this.label = 1;
                obj = cachedContentDao.getCategoryTimestamp(str, this);
                if (obj == ck1Var) {
                    return ck1Var;
                }
            } else {
                if (i != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(obj);
            }
            Long l = (Long) obj;
            if (l == null) {
                return null;
            }
            return Boxing.boxLong(System.currentTimeMillis() - l.longValue());
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.CacheRepository$getCachedContent$2, reason: invalid class name and case insensitive filesystem */
    @Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0003\u001a\n\u0012\u0004\u0012\u00020\u0002\u0018\u00010\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0003\u0010\u0004"}, d2 = {"Lak1;", "", "Lcom/strmr/ps/data/model/ContentItem;", "<anonymous>", "(Lak1;)Ljava/util/List;"}, k = 3, mv = {2, 0, 0})
    @DebugMetadata(c = "com.strmr.ps.data.repository.CacheRepository$getCachedContent$2", f = "CacheRepository.kt", i = {}, l = {73}, m = "invokeSuspend", n = {}, s = {})
    @vx8
    public static final class C02882 extends SuspendLambda implements gr3<ak1, Continuation<? super List<? extends ContentItem>>, Object> {
        final /* synthetic */ String $category;
        int label;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C02882(String str, Continuation<? super C02882> continuation) {
            super(2, continuation);
            this.$category = str;
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            return CacheRepository.this.new C02882(this.$category, continuation);
        }

        @Override // defpackage.gr3
        public final Object invoke(ak1 ak1Var, Continuation<? super List<ContentItem>> continuation) {
            return ((C02882) create(ak1Var, continuation)).invokeSuspend(e6a.a);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) {
            ck1 ck1Var = ck1.a;
            int i = this.label;
            if (i == 0) {
                s38.b(obj);
                CachedContentDao cachedContentDao = CacheRepository.this.cachedContentDao;
                String str = this.$category;
                this.label = 1;
                obj = cachedContentDao.getContentByCategory(str, this);
                if (obj == ck1Var) {
                    return ck1Var;
                }
            } else {
                if (i != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(obj);
            }
            List list = (List) obj;
            if (list.isEmpty()) {
                return null;
            }
            List list2 = list;
            ArrayList arrayList = new ArrayList(y41.p(list2, 10));
            Iterator it = list2.iterator();
            while (it.hasNext()) {
                arrayList.add(((CachedContent) it.next()).toContentItem());
            }
            return arrayList;
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.CacheRepository$getCachedPage$2, reason: invalid class name and case insensitive filesystem */
    @Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0003\u001a\b\u0012\u0004\u0012\u00020\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0003\u0010\u0004"}, d2 = {"Lak1;", "", "Lcom/strmr/ps/data/model/ContentItem;", "<anonymous>", "(Lak1;)Ljava/util/List;"}, k = 3, mv = {2, 0, 0})
    @DebugMetadata(c = "com.strmr.ps.data.repository.CacheRepository$getCachedPage$2", f = "CacheRepository.kt", i = {}, l = {85}, m = "invokeSuspend", n = {}, s = {})
    @vx8
    public static final class C02892 extends SuspendLambda implements gr3<ak1, Continuation<? super List<? extends ContentItem>>, Object> {
        final /* synthetic */ String $category;
        final /* synthetic */ int $page;
        final /* synthetic */ int $pageSize;
        int label;
        final /* synthetic */ CacheRepository this$0;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C02892(int i, int i2, CacheRepository cacheRepository, String str, Continuation<? super C02892> continuation) {
            super(2, continuation);
            this.$page = i;
            this.$pageSize = i2;
            this.this$0 = cacheRepository;
            this.$category = str;
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            return new C02892(this.$page, this.$pageSize, this.this$0, this.$category, continuation);
        }

        @Override // defpackage.gr3
        public final Object invoke(ak1 ak1Var, Continuation<? super List<ContentItem>> continuation) {
            return ((C02892) create(ak1Var, continuation)).invokeSuspend(e6a.a);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) {
            ck1 ck1Var = ck1.a;
            int i = this.label;
            if (i == 0) {
                s38.b(obj);
                int i2 = (this.$page - 1) * this.$pageSize;
                CachedContentDao cachedContentDao = this.this$0.cachedContentDao;
                String str = this.$category;
                int i3 = this.$pageSize;
                this.label = 1;
                obj = cachedContentDao.getContentPage(str, i3, i2, this);
                if (obj == ck1Var) {
                    return ck1Var;
                }
            } else {
                if (i != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(obj);
            }
            Iterable iterable = (Iterable) obj;
            ArrayList arrayList = new ArrayList(y41.p(iterable, 10));
            Iterator it = iterable.iterator();
            while (it.hasNext()) {
                arrayList.add(((CachedContent) it.next()).toContentItem());
            }
            return arrayList;
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.CacheRepository$isCacheFresh$2, reason: invalid class name and case insensitive filesystem */
    @Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0010\u000b\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "", "<anonymous>", "(Lak1;)Z"}, k = 3, mv = {2, 0, 0})
    @DebugMetadata(c = "com.strmr.ps.data.repository.CacheRepository$isCacheFresh$2", f = "CacheRepository.kt", i = {}, l = {28}, m = "invokeSuspend", n = {}, s = {})
    public static final class C02902 extends SuspendLambda implements gr3<ak1, Continuation<? super Boolean>, Object> {
        final /* synthetic */ String $category;
        int label;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C02902(String str, Continuation<? super C02902> continuation) {
            super(2, continuation);
            this.$category = str;
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
            return CacheRepository.this.new C02902(this.$category, continuation);
        }

        @Override // defpackage.gr3
        public final Object invoke(ak1 ak1Var, Continuation<? super Boolean> continuation) {
            return ((C02902) create(ak1Var, continuation)).invokeSuspend(e6a.a);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) {
            ck1 ck1Var = ck1.a;
            int i = this.label;
            if (i == 0) {
                s38.b(obj);
                CachedContentDao cachedContentDao = CacheRepository.this.cachedContentDao;
                String str = this.$category;
                this.label = 1;
                obj = cachedContentDao.getCategoryTimestamp(str, this);
                if (obj == ck1Var) {
                    return ck1Var;
                }
            } else {
                if (i != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(obj);
            }
            Long l = (Long) obj;
            if (l == null) {
                return Boxing.boxBoolean(false);
            }
            return Boxing.boxBoolean(System.currentTimeMillis() - l.longValue() < CacheRepository.this.getTTLForCategory(this.$category));
        }
    }

    static {
        TimeUnit timeUnit = TimeUnit.HOURS;
        LIST_TTL = timeUnit.toMillis(24L);
        TRAKT_LIST_TTL = timeUnit.toMillis(6L);
        TimeUnit timeUnit2 = TimeUnit.DAYS;
        DETAILS_TTL = timeUnit2.toMillis(7L);
        MAX_CACHE_AGE = timeUnit2.toMillis(30L);
    }

    @Inject
    public CacheRepository(@kp6 CachedContentDao cachedContentDao) {
        cr4.g(cachedContentDao, "cachedContentDao");
        this.cachedContentDao = cachedContentDao;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final long getTTLForCategory(String category) {
        if (!n89.ar(category, "TRENDING", false) && !n89.ar(category, "POPULAR", false)) {
            return n89.ar(category, "TRAKT_LIST", false) ? TRAKT_LIST_TTL : DETAILS_TTL;
        }
        return LIST_TTL;
    }

    @pq6
    public final Object cacheContent(@kp6 String str, @kp6 List<ContentItem> list, @kp6 Continuation<? super e6a> continuation) throws Throwable {
        m12 m12Var = sc2.a;
        Object objF = wj0.f(m02.c, new AnonymousClass2(list, this, str, null), continuation);
        return objF == ck1.a ? objF : e6a.a;
    }

    @pq6
    public final Object cacheContentPage(@kp6 String str, @kp6 List<ContentItem> list, int i, int i2, @kp6 Continuation<? super e6a> continuation) throws Throwable {
        m12 m12Var = sc2.a;
        Object objF = wj0.f(m02.c, new C02842(list, i, i2, this, str, null), continuation);
        return objF == ck1.a ? objF : e6a.a;
    }

    @pq6
    public final Object cleanupOldCache(@kp6 Continuation<? super e6a> continuation) throws Throwable {
        m12 m12Var = sc2.a;
        Object objF = wj0.f(m02.c, new C02852(null), continuation);
        return objF == ck1.a ? objF : e6a.a;
    }

    @pq6
    public final Object clearCategoryCache(@kp6 String str, @kp6 Continuation<? super e6a> continuation) throws Throwable {
        m12 m12Var = sc2.a;
        Object objF = wj0.f(m02.c, new C02862(str, null), continuation);
        return objF == ck1.a ? objF : e6a.a;
    }

    @pq6
    public final Object getCacheAge(@kp6 String str, @kp6 Continuation<? super Long> continuation) {
        m12 m12Var = sc2.a;
        return wj0.f(m02.c, new C02872(str, null), continuation);
    }

    @pq6
    public final Object getCachedContent(@kp6 String str, @kp6 Continuation<? super List<ContentItem>> continuation) {
        m12 m12Var = sc2.a;
        return wj0.f(m02.c, new C02882(str, null), continuation);
    }

    @pq6
    public final Object getCachedPage(@kp6 String str, int i, int i2, @kp6 Continuation<? super List<ContentItem>> continuation) {
        m12 m12Var = sc2.a;
        return wj0.f(m02.c, new C02892(i, i2, this, str, null), continuation);
    }

    @pq6
    public final Object isCacheFresh(@kp6 String str, @kp6 Continuation<? super Boolean> continuation) {
        m12 m12Var = sc2.a;
        return wj0.f(m02.c, new C02902(str, null), continuation);
    }
}
