package com.vinfast.companion.mqttkit.source;

/* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
@kotlin.Metadata(d1 = {"\u0000\n\n\u0000\n\u0002\u0010\u0002\n\u0002\u0018\u0002\u0010\u0000\u001a\u00020\u0001*\u00020\u0002H\n"}, d2 = {"<anonymous>", "", "Lkotlinx/coroutines/CoroutineScope;"}, k = 3, mv = {2, 2, 0}, xi = 48)
@kotlin.coroutines.jvm.internal.DebugMetadata(c = "com.vinfast.companion.mqttkit.source.AwsMqttProvider$connect$1", f = "AwsMqttProvider.kt", l = {111}, m = "invokeSuspend", v = 1)
final class AwsMqttProvider$connect$1 extends kotlin.coroutines.jvm.internal.SuspendLambda implements kotlin.jvm.functions.Function2<kotlinx.coroutines.CoroutineScope, kotlin.coroutines.Continuation<? super kotlin.Unit>, java.lang.Object> {
    long n;
    java.lang.Object o;
    int p;
    final /* synthetic */ com.vinfast.companion.mqttkit.source.AwsMqttProvider q;
    final /* synthetic */ java.lang.String r;
    final /* synthetic */ com.amazonaws.mobileconnectors.iot.AWSIotMqttManager s;

    /* JADX INFO: renamed from: com.vinfast.companion.mqttkit.source.AwsMqttProvider$connect$1$1, reason: invalid class name */
    /* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
    @kotlin.Metadata(k = 3, mv = {2, 2, 0}, xi = 48)
    static final /* synthetic */ class AnonymousClass1 extends kotlin.jvm.internal.AdaptedFunctionReference implements kotlin.jvm.functions.Function1<java.lang.String, kotlin.Unit> {
        AnonymousClass1(java.lang.Object obj) {
            super(1, obj, timber.log.Timber.Tree.class, "d", "d(Ljava/lang/String;[Ljava/lang/Object;)V", 0);
        }

        public final void a(java.lang.String str) {
            ((timber.log.Timber.Tree) ((kotlin.jvm.internal.AdaptedFunctionReference) this).a).a(str, new java.lang.Object[0]);
        }

        public /* bridge */ /* synthetic */ java.lang.Object invoke(java.lang.Object obj) {
            a((java.lang.String) obj);
            return kotlin.Unit.a;
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    AwsMqttProvider$connect$1(com.vinfast.companion.mqttkit.source.AwsMqttProvider awsMqttProvider, java.lang.String str, com.amazonaws.mobileconnectors.iot.AWSIotMqttManager aWSIotMqttManager, kotlin.coroutines.Continuation continuation) {
        super(2, continuation);
        this.q = awsMqttProvider;
        this.r = str;
        this.s = aWSIotMqttManager;
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX INFO: Thrown type has an unknown type hierarchy: kotlin.NoWhenBranchMatchedException */
    public static final void j(com.vinfast.companion.mqttkit.source.AwsMqttProvider awsMqttProvider, long j, java.lang.String str, com.amazonaws.mobileconnectors.iot.AWSIotMqttClientStatusCallback.AWSIotMqttClientStatus aWSIotMqttClientStatus, java.lang.Throwable th) throws kotlin.NoWhenBranchMatchedException {
        com.vinfast.companion.mqttkit.source.MqttSourceCallback mqttSourceCallback = awsMqttProvider.callback;
        if (mqttSourceCallback != null) {
            mqttSourceCallback.i(aWSIotMqttClientStatus.name());
        }
        java.lang.String str2 = "🐛 " + awsMqttProvider.myRef.b() + " CONNECTION STATE = " + aWSIotMqttClientStatus;
        timber.log.Timber.Forest forest = timber.log.Timber.a;
        awsMqttProvider.m(str2, new com.vinfast.companion.mqttkit.source.AwsMqttProvider$connect$1$clientStatusCallback$1$1(forest.t("[MQTT]")));
        if (th != null) {
            forest.t("[MQTT]").q("💩 " + awsMqttProvider.myRef.c() + " EXCEPTION = " + th.getLocalizedMessage(), new java.lang.Object[0]);
        }
        if (aWSIotMqttClientStatus == com.amazonaws.mobileconnectors.iot.AWSIotMqttClientStatusCallback.AWSIotMqttClientStatus.Connected) {
            long jNanoTime = (java.lang.System.nanoTime() - j) / ((long) 1000000);
            forest.t("[MQTT]").a("🚀 MQTT FULL CONNECT TIME = " + jNanoTime + " ms", new java.lang.Object[0]);
            awsMqttProvider.o(str);
        }
    }

    public final kotlin.coroutines.Continuation create(java.lang.Object obj, kotlin.coroutines.Continuation continuation) {
        return new com.vinfast.companion.mqttkit.source.AwsMqttProvider$connect$1(this.q, this.r, this.s, continuation);
    }

    public final java.lang.Object invokeSuspend(java.lang.Object obj) {
        com.amazonaws.mobileconnectors.iot.AWSIotMqttClientStatusCallback aWSIotMqttClientStatusCallback;
        java.lang.Object objG = kotlin.coroutines.intrinsics.IntrinsicsKt.g();
        int i = this.p;
        try {
            if (i == 0) {
                kotlin.ResultKt.b(obj);
                com.vinfast.companion.mqttkit.source.AwsMqttProvider awsMqttProvider = this.q;
                awsMqttProvider.m("🟢 " + awsMqttProvider.myRef.c() + " START CONNECT MQTT WITH VINCODE: " + this.r, new com.vinfast.companion.mqttkit.source.AwsMqttProvider$connect$1.AnonymousClass1(timber.log.Timber.a.t("[MQTT]")));
                final long jNanoTime = java.lang.System.nanoTime();
                final com.vinfast.companion.mqttkit.source.AwsMqttProvider awsMqttProvider2 = this.q;
                final java.lang.String str = this.r;
                com.amazonaws.mobileconnectors.iot.AWSIotMqttClientStatusCallback aWSIotMqttClientStatusCallback2 = new com.amazonaws.mobileconnectors.iot.AWSIotMqttClientStatusCallback() { // from class: com.vinfast.companion.mqttkit.source.c
                    /* JADX INFO: Thrown type has an unknown type hierarchy: kotlin.NoWhenBranchMatchedException */
                    public final void onStatusChanged(com.amazonaws.mobileconnectors.iot.AWSIotMqttClientStatusCallback.AWSIotMqttClientStatus aWSIotMqttClientStatus, java.lang.Throwable th) throws kotlin.NoWhenBranchMatchedException {
                        com.vinfast.companion.mqttkit.source.AwsMqttProvider$connect$1.j(awsMqttProvider2, jNanoTime, str, aWSIotMqttClientStatus, th);
                    }
                };
                com.vinfast.companion.mqttkit.source.AwsIotCredentialsProvider awsIotCredentialsProvider = this.q.provider;
                java.lang.String str2 = this.r;
                this.o = aWSIotMqttClientStatusCallback2;
                this.n = jNanoTime;
                this.p = 1;
                if (awsIotCredentialsProvider.j(str2, this) == objG) {
                    return objG;
                }
                aWSIotMqttClientStatusCallback = aWSIotMqttClientStatusCallback2;
            } else {
                if (i != 1) {
                    throw new java.lang.IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                aWSIotMqttClientStatusCallback = (com.amazonaws.mobileconnectors.iot.AWSIotMqttClientStatusCallback) this.o;
                kotlin.ResultKt.b(obj);
            }
            this.s.connect(this.q.provider, aWSIotMqttClientStatusCallback);
        } catch (java.lang.Exception e) {
            timber.log.Timber.a.t("[MQTT]").q("💩 " + this.q.myRef.c() + " IGNORE EXCEPTION = " + e.getLocalizedMessage(), new java.lang.Object[0]);
        }
        return kotlin.Unit.a;
    }

    public final java.lang.Object invoke(kotlinx.coroutines.CoroutineScope coroutineScope, kotlin.coroutines.Continuation continuation) {
        return create(coroutineScope, continuation).invokeSuspend(kotlin.Unit.a);
    }
}
