package com.sistemasolton.itranvias;

import android.nfc.Tag;
import android.nfc.tech.IsoDep;
import com.sistemasolton.itranvias.MainActivity;
import kotlin.Metadata;
import kotlin.Result;
import kotlin.ResultKt;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.intrinsics.IntrinsicsKt;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;
import kotlin.jvm.functions.Function2;
import kotlin.jvm.internal.Intrinsics;
import kotlinx.coroutines.CoroutineScope;

/* JADX INFO: compiled from: CardRepositoryImpl.kt */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u0000\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\u0010\u0000\u001a\b\u0012\u0004\u0012\u00020\u00020\u0001*\u00020\u0003H\n"}, d2 = {"<anonymous>", "Lkotlin/Result;", "Lcom/sistemasolton/itranvias/MainActivity$CardData;", "Lkotlinx/coroutines/CoroutineScope;"}, k = 3, mv = {2, 1, 0}, xi = 48)
@DebugMetadata(c = "com.sistemasolton.itranvias.CardRepositoryImpl$getCard$2", f = "CardRepositoryImpl.kt", i = {}, l = {}, m = "invokeSuspend", n = {}, s = {})
final class CardRepositoryImpl$getCard$2 extends SuspendLambda implements Function2<CoroutineScope, Continuation<? super Result<? extends MainActivity.CardData>>, Object> {
    final /* synthetic */ Tag $tag;
    int label;
    final /* synthetic */ CardRepositoryImpl this$0;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    CardRepositoryImpl$getCard$2(Tag tag, CardRepositoryImpl cardRepositoryImpl, Continuation<? super CardRepositoryImpl$getCard$2> continuation) {
        super(2, continuation);
        this.$tag = tag;
        this.this$0 = cardRepositoryImpl;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation<Unit> create(Object obj, Continuation<?> continuation) {
        return new CardRepositoryImpl$getCard$2(this.$tag, this.this$0, continuation);
    }

    @Override // kotlin.jvm.functions.Function2
    public /* bridge */ /* synthetic */ Object invoke(CoroutineScope coroutineScope, Continuation<? super Result<? extends MainActivity.CardData>> continuation) {
        return invoke2(coroutineScope, (Continuation<? super Result<MainActivity.CardData>>) continuation);
    }

    /* JADX INFO: renamed from: invoke, reason: avoid collision after fix types in other method */
    public final Object invoke2(CoroutineScope coroutineScope, Continuation<? super Result<MainActivity.CardData>> continuation) {
        return ((CardRepositoryImpl$getCard$2) create(coroutineScope, continuation)).invokeSuspend(Unit.INSTANCE);
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Object invokeSuspend(Object obj) throws Throwable {
        Object objM8388constructorimpl;
        IntrinsicsKt.getCOROUTINE_SUSPENDED();
        if (this.label != 0) {
            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
        ResultKt.throwOnFailure(obj);
        try {
            IsoDep isoDep = IsoDep.get(this.$tag);
            isoDep.connect();
            Intrinsics.checkNotNull(isoDep);
            byte[] bArrSelectTransportNetwork = CardRepositoryImplKt.selectTransportNetwork(isoDep);
            CardRepositoryImplKt.readEnvironment(isoDep);
            byte[] contract = CardRepositoryImplKt.readContract(isoDep);
            String cardId = this.this$0.getCardId(bArrSelectTransportNetwork);
            double intBigEndian = ((double) CardRepositoryImplKt.toIntBigEndian(contract, 29, 3)) / 100.0d;
            isoDep.close();
            Result.Companion companion = Result.INSTANCE;
            objM8388constructorimpl = Result.m8388constructorimpl(new MainActivity.CardData(cardId, Boxing.boxDouble(intBigEndian), null, 4, null));
        } catch (Exception e) {
            Result.Companion companion2 = Result.INSTANCE;
            objM8388constructorimpl = Result.m8388constructorimpl(ResultKt.createFailure(e));
        }
        return Result.m8387boximpl(objM8388constructorimpl);
    }
}