package com.vinfast.companion.serviceskit.worker;

/* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
/* JADX INFO: loaded from: E:\ios\vf_dex\classes6.dex */
@kotlin.Metadata(d1 = {"\u0000\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\u0010\u0000\u001a\u00070\u0001¢\u0006\u0002\b\u0002*\u00020\u0003H\n"}, d2 = {"<anonymous>", "Landroidx/work/ListenableWorker$Result;", "Lkotlin/jvm/internal/EnhancedNullability;", "Lkotlinx/coroutines/CoroutineScope;"}, k = 3, mv = {2, 2, 0}, xi = 48)
@kotlin.coroutines.jvm.internal.DebugMetadata(c = "com.vinfast.companion.serviceskit.worker.CalendarSyncWorker$doWork$2", f = "CalendarSyncWorker.kt", l = {60}, m = "invokeSuspend", v = 1)
@kotlin.jvm.internal.SourceDebugExtension
final class CalendarSyncWorker$doWork$2 extends kotlin.coroutines.jvm.internal.SuspendLambda implements kotlin.jvm.functions.Function2<kotlinx.coroutines.CoroutineScope, kotlin.coroutines.Continuation<? super androidx.work.ListenableWorker.Result>, java.lang.Object> {
    boolean n;
    java.lang.Object o;
    java.lang.Object p;
    java.lang.Object q;
    java.lang.Object r;
    int s;
    final /* synthetic */ com.vinfast.companion.serviceskit.worker.CalendarSyncWorker t;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    CalendarSyncWorker$doWork$2(com.vinfast.companion.serviceskit.worker.CalendarSyncWorker calendarSyncWorker, kotlin.coroutines.Continuation continuation) {
        super(2, continuation);
        this.t = calendarSyncWorker;
    }

    public final kotlin.coroutines.Continuation create(java.lang.Object obj, kotlin.coroutines.Continuation continuation) {
        return new com.vinfast.companion.serviceskit.worker.CalendarSyncWorker$doWork$2(this.t, continuation);
    }

    public final java.lang.Object invokeSuspend(java.lang.Object obj) {
        java.lang.Object objG = kotlin.coroutines.intrinsics.IntrinsicsKt.g();
        int i = this.s;
        try {
            if (i == 0) {
                kotlin.ResultKt.b(obj);
                timber.log.Timber.Forest forest = timber.log.Timber.a;
                forest.j("[HERE-34] ===> CalendarSyncWorker.doWork", new java.lang.Object[0]);
                boolean zC = this.t.f().c("key_from_setting", false);
                okhttp3.MultipartBody.Builder type = new okhttp3.MultipartBody.Builder((java.lang.String) null, 1, (kotlin.jvm.internal.DefaultConstructorMarker) null).setType(okhttp3.MultipartBody.FORM);
                org.json.JSONArray jSONArrayB = com.vinfast.companion.serviceskit.manager.CalendarManager.a.b(this.t.context);
                java.lang.String str = "vfcalendar_" + com.vinfast.companion.core.base.storage.AppSharedPreference.l(this.t.prefs, "current_user_email", (java.lang.String) null, 2, (java.lang.Object) null) + ".txt";
                java.io.File file = new java.io.File(this.t.context.getFilesDir(), str);
                if (!file.exists()) {
                    file.createNewFile();
                }
                java.io.FileOutputStream fileOutputStreamOpenFileOutput = this.t.context.openFileOutput(str, 0);
                try {
                    java.lang.String string = jSONArrayB.toString();
                    kotlin.jvm.internal.Intrinsics.k(string, "toString(...)");
                    byte[] bytes = string.getBytes(kotlin.text.Charsets.b);
                    kotlin.jvm.internal.Intrinsics.k(bytes, "getBytes(...)");
                    fileOutputStreamOpenFileOutput.write(bytes);
                    kotlin.Unit unit = kotlin.Unit.a;
                    kotlin.io.CloseableKt.a(fileOutputStreamOpenFileOutput, (java.lang.Throwable) null);
                    if (zC) {
                        com.vinfast.companion.core.utils.FileUtils fileUtils = com.vinfast.companion.core.utils.FileUtils.a;
                        com.vinfast.companion.core.base.storage.AppSharedPreference appSharedPreference = this.t.prefs;
                        java.lang.String strL = com.vinfast.companion.core.base.storage.AppSharedPreference.l(appSharedPreference, "calendar_sync_checksum_" + com.vinfast.companion.core.base.storage.AppSharedPreference.l(appSharedPreference, "current_user_email", (java.lang.String) null, 2, (java.lang.Object) null), (java.lang.String) null, 2, (java.lang.Object) null);
                        if (strL == null) {
                            strL = "";
                        }
                        if (fileUtils.b(strL, file)) {
                            forest.j("[HERE-53] ===> CalendarSyncWorker.success (not sync)", new java.lang.Object[0]);
                            return androidx.work.ListenableWorker.Result.c();
                        }
                    }
                    com.vinfast.companion.core.base.storage.AppSharedPreference appSharedPreference2 = this.t.prefs;
                    java.lang.String strA = com.vinfast.companion.core.utils.FileUtils.a.a(file);
                    java.lang.String str2 = strA != null ? strA : "";
                    appSharedPreference2.s("calendar_sync_checksum_" + com.vinfast.companion.core.base.storage.AppSharedPreference.l(appSharedPreference2, "current_user_email", (java.lang.String) null, 2, (java.lang.Object) null), str2);
                    forest.a("CalendarSyncWorker: " + jSONArrayB, new java.lang.Object[0]);
                    type.addFormDataPart("file", str, okhttp3.RequestBody.Companion.create$default(okhttp3.RequestBody.Companion, file, (okhttp3.MediaType) null, 1, (java.lang.Object) null));
                    com.vinfast.companion.serviceskit.data.repository.DataSyncRepositoryProvider dataSyncRepositoryProvider = this.t.dataSyncRepositoryProvider;
                    okhttp3.MultipartBody multipartBodyBuild = type.build();
                    this.o = kotlin.coroutines.jvm.internal.SpillingKt.a(type);
                    this.p = kotlin.coroutines.jvm.internal.SpillingKt.a(jSONArrayB);
                    this.q = kotlin.coroutines.jvm.internal.SpillingKt.a(str);
                    this.r = kotlin.coroutines.jvm.internal.SpillingKt.a(file);
                    this.n = zC;
                    this.s = 1;
                    if (dataSyncRepositoryProvider.b("calendar", multipartBodyBuild, this) == objG) {
                        return objG;
                    }
                } catch (java.lang.Throwable th) {
                    try {
                        throw th;
                    } catch (java.lang.Throwable th2) {
                        kotlin.io.CloseableKt.a(fileOutputStreamOpenFileOutput, th);
                        throw th2;
                    }
                }
            } else {
                if (i != 1) {
                    throw new java.lang.IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                kotlin.ResultKt.b(obj);
            }
            timber.log.Timber.a.j("[HERE-61] ===> CalendarSyncWorker.success", new java.lang.Object[0]);
            return androidx.work.ListenableWorker.Result.c();
        } catch (java.lang.Exception unused) {
            timber.log.Timber.a.j("[HERE-64] ===> CalendarSyncWorker.failure", new java.lang.Object[0]);
            return androidx.work.ListenableWorker.Result.a();
        }
    }

    public final java.lang.Object invoke(kotlinx.coroutines.CoroutineScope coroutineScope, kotlin.coroutines.Continuation continuation) {
        return create(coroutineScope, continuation).invokeSuspend(kotlin.Unit.a);
    }
}
