package fg;

import ca.canadapost.core.data.aws.model.CategoryEnum;
import ca.canadapost.core.data.aws.model.SubscriptionItem;
import ca.canadapost.module.track.model.CloudToLocalItems;
import ca.canadapost.module.track.model.PackageItemModel;
import com.amplifyframework.datastore.generated.model.TrackItemSource;
import com.amplifyframework.datastore.generated.model.TrackSyncItem;
import dn.p;
import ig.a;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import kotlin.coroutines.jvm.internal.l;
import kotlin.jvm.internal.t;
import rm.n0;
import rm.y;
import sm.v;
import tp.a1;
import tp.i0;
import tp.m0;

/* loaded from: classes4.dex */
public final class d implements fg.a {

    /* renamed from: a, reason: collision with root package name */
    private final eg.a f18250a;

    /* renamed from: b, reason: collision with root package name */
    private final gg.b f18251b;

    /* renamed from: c, reason: collision with root package name */
    private final g9.d f18252c;

    /* renamed from: d, reason: collision with root package name */
    private final j9.c f18253d;

    /* renamed from: e, reason: collision with root package name */
    private final ca.a f18254e;

    /* renamed from: f, reason: collision with root package name */
    private final ja.d f18255f;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class a extends kotlin.coroutines.jvm.internal.d {

        /* renamed from: p, reason: collision with root package name */
        Object f18256p;

        /* renamed from: q, reason: collision with root package name */
        Object f18257q;

        /* renamed from: r, reason: collision with root package name */
        /* synthetic */ Object f18258r;

        /* renamed from: t, reason: collision with root package name */
        int f18260t;

        a(vm.d dVar) {
            super(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f18258r = obj;
            this.f18260t |= Integer.MIN_VALUE;
            return d.this.f(null, null, this);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class b extends kotlin.coroutines.jvm.internal.d {

        /* renamed from: p, reason: collision with root package name */
        Object f18261p;

        /* renamed from: q, reason: collision with root package name */
        Object f18262q;

        /* renamed from: r, reason: collision with root package name */
        Object f18263r;

        /* renamed from: s, reason: collision with root package name */
        Object f18264s;

        /* renamed from: t, reason: collision with root package name */
        Object f18265t;

        /* renamed from: u, reason: collision with root package name */
        Object f18266u;

        /* renamed from: v, reason: collision with root package name */
        Object f18267v;

        /* renamed from: w, reason: collision with root package name */
        /* synthetic */ Object f18268w;

        /* renamed from: y, reason: collision with root package name */
        int f18270y;

        b(vm.d dVar) {
            super(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f18268w = obj;
            this.f18270y |= Integer.MIN_VALUE;
            return d.this.g(null, null, this);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class c extends kotlin.coroutines.jvm.internal.d {

        /* renamed from: p, reason: collision with root package name */
        Object f18271p;

        /* renamed from: q, reason: collision with root package name */
        Object f18272q;

        /* renamed from: r, reason: collision with root package name */
        Object f18273r;

        /* renamed from: s, reason: collision with root package name */
        /* synthetic */ Object f18274s;

        /* renamed from: u, reason: collision with root package name */
        int f18276u;

        c(vm.d dVar) {
            super(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f18274s = obj;
            this.f18276u |= Integer.MIN_VALUE;
            return d.this.a(this);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: fg.d$d, reason: collision with other inner class name */
    /* loaded from: classes4.dex */
    public static final class C0400d extends l implements p {

        /* renamed from: p, reason: collision with root package name */
        int f18277p;

        C0400d(vm.d dVar) {
            super(2, dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final vm.d create(Object obj, vm.d dVar) {
            return new C0400d(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            wm.d.f();
            if (this.f18277p != 0) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            y.b(obj);
            return d.this.f18250a.getAll();
        }

        @Override // dn.p
        public final Object invoke(m0 m0Var, vm.d dVar) {
            return ((C0400d) create(m0Var, dVar)).invokeSuspend(n0.f34904a);
        }
    }

    public d(eg.a dao, gg.b cloudApi, g9.d sessionRepository, j9.c awsPushService, ca.a languageService, ja.d sharedPreferencesService) {
        t.g(dao, "dao");
        t.g(cloudApi, "cloudApi");
        t.g(sessionRepository, "sessionRepository");
        t.g(awsPushService, "awsPushService");
        t.g(languageService, "languageService");
        t.g(sharedPreferencesService, "sharedPreferencesService");
        this.f18250a = dao;
        this.f18251b = cloudApi;
        this.f18252c = sessionRepository;
        this.f18253d = awsPushService;
        this.f18254e = languageService;
        this.f18255f = sharedPreferencesService;
    }

    private final void c(CloudToLocalItems cloudToLocalItems) {
        ArrayList arrayList = new ArrayList(cloudToLocalItems.getNewItems().values());
        ArrayList<PackageItemModel> arrayList2 = new ArrayList(cloudToLocalItems.getUpdatingItems().values());
        ArrayList<PackageItemModel> arrayList3 = new ArrayList(cloudToLocalItems.getDeletingItems().values());
        ArrayList arrayList4 = new ArrayList();
        ArrayList arrayList5 = new ArrayList();
        Iterator it = arrayList.iterator();
        while (true) {
            String str = "";
            if (!it.hasNext()) {
                break;
            }
            PackageItemModel packageItemModel = (PackageItemModel) it.next();
            String itemNumber = packageItemModel.getItemNumber();
            CategoryEnum categoryEnum = CategoryEnum.trackItem;
            String userDescription = packageItemModel.getUserDescription();
            if (userDescription != null) {
                str = userDescription;
            }
            arrayList4.add(new SubscriptionItem(itemNumber, categoryEnum, str));
        }
        for (PackageItemModel packageItemModel2 : arrayList2) {
            String itemNumber2 = packageItemModel2.getItemNumber();
            CategoryEnum categoryEnum2 = CategoryEnum.trackItem;
            String userDescription2 = packageItemModel2.getUserDescription();
            if (userDescription2 == null) {
                userDescription2 = "";
            }
            arrayList4.add(new SubscriptionItem(itemNumber2, categoryEnum2, userDescription2));
        }
        for (PackageItemModel packageItemModel3 : arrayList3) {
            String itemNumber3 = packageItemModel3.getItemNumber();
            CategoryEnum categoryEnum3 = CategoryEnum.trackItem;
            String userDescription3 = packageItemModel3.getUserDescription();
            if (userDescription3 == null) {
                userDescription3 = "";
            }
            arrayList5.add(new SubscriptionItem(itemNumber3, categoryEnum3, userDescription3));
        }
        if (!arrayList4.isEmpty()) {
            this.f18253d.c(arrayList4, false);
        }
        if (!arrayList5.isEmpty()) {
            this.f18253d.d(arrayList5, false);
        }
    }

    private final CloudToLocalItems d(Map map, Map map2) {
        boolean booleanValue;
        boolean booleanValue2;
        boolean booleanValue3;
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        LinkedHashMap linkedHashMap2 = new LinkedHashMap();
        LinkedHashMap linkedHashMap3 = new LinkedHashMap();
        for (Map.Entry entry : map.entrySet()) {
            String str = (String) entry.getKey();
            TrackSyncItem trackSyncItem = (TrackSyncItem) entry.getValue();
            PackageItemModel packageItemModel = (PackageItemModel) map2.get(str);
            a.C0491a c0491a = ig.a.f23217a;
            boolean z10 = !c0491a.c(trackSyncItem);
            boolean z11 = false;
            if (packageItemModel == null) {
                if (z10) {
                    boolean z12 = trackSyncItem.getSource() == TrackItemSource.SET_AND_FORGET;
                    String userDescription = trackSyncItem.getUserDescription();
                    Date date = trackSyncItem.getUpdatedAt().toDate();
                    t.f(date, "toDate(...)");
                    Date date2 = trackSyncItem.getCreatedAt().toDate();
                    t.f(date2, "toDate(...)");
                    Boolean isRead = trackSyncItem.getIsRead();
                    if (isRead == null) {
                        booleanValue = false;
                    } else {
                        t.d(isRead);
                        booleanValue = isRead.booleanValue();
                    }
                    Boolean isFlaggedAsNotMine = trackSyncItem.getIsFlaggedAsNotMine();
                    if (isFlaggedAsNotMine == null) {
                        booleanValue2 = false;
                    } else {
                        t.d(isFlaggedAsNotMine);
                        booleanValue2 = isFlaggedAsNotMine.booleanValue();
                    }
                    linkedHashMap.put(str, new PackageItemModel(str, userDescription, date, date2, false, false, null, null, null, null, null, null, null, null, null, z12, booleanValue, booleanValue2, 32752, null));
                }
            } else if (!c0491a.e(packageItemModel, trackSyncItem)) {
                if (z10) {
                    packageItemModel.setUserDescription(trackSyncItem.getUserDescription());
                    Date date3 = trackSyncItem.getUpdatedAt().toDate();
                    t.f(date3, "toDate(...)");
                    packageItemModel.setModifiedAt(date3);
                    packageItemModel.setCloudId(trackSyncItem.getId());
                    Date date4 = trackSyncItem.getCreatedAt().toDate();
                    t.f(date4, "toDate(...)");
                    packageItemModel.setCreatedAt(date4);
                    packageItemModel.setDeleted(false);
                    if (!packageItemModel.isSNFItemRead()) {
                        Boolean isRead2 = trackSyncItem.getIsRead();
                        if (isRead2 == null) {
                            booleanValue3 = false;
                        } else {
                            t.d(isRead2);
                            booleanValue3 = isRead2.booleanValue();
                        }
                        packageItemModel.setSNFItemRead(booleanValue3);
                    }
                    Boolean isFlaggedAsNotMine2 = trackSyncItem.getIsFlaggedAsNotMine();
                    if (isFlaggedAsNotMine2 != null) {
                        t.d(isFlaggedAsNotMine2);
                        z11 = isFlaggedAsNotMine2.booleanValue();
                    }
                    packageItemModel.setFlaggedAsNotMine(z11);
                    linkedHashMap3.put(str, packageItemModel);
                } else {
                    packageItemModel.setDeleted(true);
                    Date date5 = trackSyncItem.getUpdatedAt().toDate();
                    t.f(date5, "toDate(...)");
                    packageItemModel.setModifiedAt(date5);
                    packageItemModel.setCloudId(null);
                    linkedHashMap2.put(str, packageItemModel);
                }
            }
        }
        return new CloudToLocalItems(linkedHashMap, linkedHashMap2, linkedHashMap3);
    }

    private final boolean e() {
        String h10 = this.f18254e.h();
        t.f(h10, "getLanguageCountry(...)");
        if (t.b(h10, this.f18255f.getString("LANGUAGE_COUNTRY_CODE_TRACK", ""))) {
            return false;
        }
        this.f18255f.putString("LANGUAGE_COUNTRY_CODE_TRACK", h10);
        return true;
    }

    /* JADX WARN: Removed duplicated region for block: B:22:0x0115 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:26:0x0105 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:27:0x0106  */
    /* JADX WARN: Removed duplicated region for block: B:32:0x00c9  */
    /* JADX WARN: Removed duplicated region for block: B:42:0x00e5  */
    /* JADX WARN: Removed duplicated region for block: B:49:0x00b7 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:50:0x00b8  */
    /* JADX WARN: Removed duplicated region for block: B:51:0x0079  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0028  */
    @Override // fg.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object a(vm.d dVar) {
        c cVar;
        Object f10;
        int i10;
        Object g10;
        d dVar2;
        HashMap hashMap;
        Map map;
        d dVar3;
        d dVar4;
        if (dVar instanceof c) {
            cVar = (c) dVar;
            int i11 = cVar.f18276u;
            if ((i11 & Integer.MIN_VALUE) != 0) {
                cVar.f18276u = i11 - Integer.MIN_VALUE;
                Object obj = cVar.f18274s;
                f10 = wm.d.f();
                i10 = cVar.f18276u;
                if (i10 != 0) {
                    y.b(obj);
                    if (!this.f18252c.h()) {
                        this.f18251b.b();
                        return n0.f34904a;
                    }
                    gg.b bVar = this.f18251b;
                    cVar.f18271p = this;
                    cVar.f18276u = 1;
                    obj = bVar.c(cVar);
                    if (obj == f10) {
                        return f10;
                    }
                } else if (i10 == 1) {
                    this = (d) cVar.f18271p;
                    y.b(obj);
                } else {
                    if (i10 != 2) {
                        if (i10 != 3) {
                            if (i10 != 4) {
                                if (i10 != 5) {
                                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                                }
                                y.b(obj);
                                return n0.f34904a;
                            }
                            hashMap = (HashMap) cVar.f18273r;
                            map = (Map) cVar.f18272q;
                            dVar4 = (d) cVar.f18271p;
                            y.b(obj);
                            cVar.f18271p = null;
                            cVar.f18272q = null;
                            cVar.f18273r = null;
                            cVar.f18276u = 5;
                            if (dVar4.g(map, hashMap, cVar) == f10) {
                                return f10;
                            }
                            return n0.f34904a;
                        }
                        hashMap = (HashMap) cVar.f18273r;
                        map = (Map) cVar.f18272q;
                        dVar3 = (d) cVar.f18271p;
                        y.b(obj);
                        cVar.f18271p = dVar3;
                        cVar.f18272q = map;
                        cVar.f18273r = hashMap;
                        cVar.f18276u = 4;
                        if (dVar3.f(map, hashMap, cVar) == f10) {
                            return f10;
                        }
                        dVar4 = dVar3;
                        cVar.f18271p = null;
                        cVar.f18272q = null;
                        cVar.f18273r = null;
                        cVar.f18276u = 5;
                        if (dVar4.g(map, hashMap, cVar) == f10) {
                        }
                        return n0.f34904a;
                    }
                    hashMap = (HashMap) cVar.f18273r;
                    map = (Map) cVar.f18272q;
                    dVar2 = (d) cVar.f18271p;
                    y.b(obj);
                    for (eg.d dVar5 : (Iterable) obj) {
                        PackageItemModel b10 = eg.c.f17056a.b(dVar5);
                        if (b10 != null) {
                            hashMap.put(dVar5.i(), b10);
                        }
                    }
                    if (dVar2.e()) {
                        j9.c cVar2 = dVar2.f18253d;
                        cVar.f18271p = dVar2;
                        cVar.f18272q = map;
                        cVar.f18273r = hashMap;
                        cVar.f18276u = 3;
                        if (cVar2.a(cVar) == f10) {
                            return f10;
                        }
                    }
                    dVar3 = dVar2;
                    cVar.f18271p = dVar3;
                    cVar.f18272q = map;
                    cVar.f18273r = hashMap;
                    cVar.f18276u = 4;
                    if (dVar3.f(map, hashMap, cVar) == f10) {
                    }
                }
                Map map2 = (Map) obj;
                HashMap hashMap2 = new HashMap();
                i0 b11 = a1.b();
                C0400d c0400d = new C0400d(null);
                cVar.f18271p = this;
                cVar.f18272q = map2;
                cVar.f18273r = hashMap2;
                cVar.f18276u = 2;
                g10 = tp.i.g(b11, c0400d, cVar);
                if (g10 != f10) {
                    return f10;
                }
                dVar2 = this;
                hashMap = hashMap2;
                map = map2;
                obj = g10;
                while (r12.hasNext()) {
                }
                if (dVar2.e()) {
                }
                dVar3 = dVar2;
                cVar.f18271p = dVar3;
                cVar.f18272q = map;
                cVar.f18273r = hashMap;
                cVar.f18276u = 4;
                if (dVar3.f(map, hashMap, cVar) == f10) {
                }
            }
        }
        cVar = new c(dVar);
        Object obj2 = cVar.f18274s;
        f10 = wm.d.f();
        i10 = cVar.f18276u;
        if (i10 != 0) {
        }
        Map map22 = (Map) obj2;
        HashMap hashMap22 = new HashMap();
        i0 b112 = a1.b();
        C0400d c0400d2 = new C0400d(null);
        cVar.f18271p = this;
        cVar.f18272q = map22;
        cVar.f18273r = hashMap22;
        cVar.f18276u = 2;
        g10 = tp.i.g(b112, c0400d2, cVar);
        if (g10 != f10) {
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x003c  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0023  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object f(Map map, Map map2, vm.d dVar) {
        a aVar;
        Object f10;
        int i10;
        CloudToLocalItems d10;
        int v10;
        if (dVar instanceof a) {
            aVar = (a) dVar;
            int i11 = aVar.f18260t;
            if ((i11 & Integer.MIN_VALUE) != 0) {
                aVar.f18260t = i11 - Integer.MIN_VALUE;
                Object obj = aVar.f18258r;
                f10 = wm.d.f();
                i10 = aVar.f18260t;
                if (i10 != 0) {
                    y.b(obj);
                    d10 = d(map, map2);
                    ArrayList arrayList = new ArrayList();
                    arrayList.addAll(new ArrayList(d10.getDeletingItems().values()));
                    arrayList.addAll(new ArrayList(d10.getUpdatingItems().values()));
                    arrayList.addAll(new ArrayList(d10.getNewItems().values()));
                    v10 = v.v(arrayList, 10);
                    ArrayList arrayList2 = new ArrayList(v10);
                    Iterator it = arrayList.iterator();
                    while (it.hasNext()) {
                        arrayList2.add(eg.c.f17056a.a((PackageItemModel) it.next()));
                    }
                    eg.a aVar2 = this.f18250a;
                    aVar.f18256p = this;
                    aVar.f18257q = d10;
                    aVar.f18260t = 1;
                    if (aVar2.a(arrayList2, aVar) == f10) {
                        return f10;
                    }
                } else {
                    if (i10 != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    CloudToLocalItems cloudToLocalItems = (CloudToLocalItems) aVar.f18257q;
                    d dVar2 = (d) aVar.f18256p;
                    y.b(obj);
                    d10 = cloudToLocalItems;
                    this = dVar2;
                }
                this.c(d10);
                return n0.f34904a;
            }
        }
        aVar = new a(dVar);
        Object obj2 = aVar.f18258r;
        f10 = wm.d.f();
        i10 = aVar.f18260t;
        if (i10 != 0) {
        }
        this.c(d10);
        return n0.f34904a;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:24:0x00b5  */
    /* JADX WARN: Removed duplicated region for block: B:53:0x01d1  */
    /* JADX WARN: Removed duplicated region for block: B:64:0x009c  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x002d  */
    /* JADX WARN: Type inference failed for: r11v10, types: [java.util.Map] */
    /* JADX WARN: Type inference failed for: r11v12, types: [java.util.Map] */
    /* JADX WARN: Type inference failed for: r12v16, types: [java.util.Map] */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:38:0x0118 -> B:21:0x01c2). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:49:0x01a5 -> B:19:0x01af). Please report as a decompilation issue!!! */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object g(Map map, Map map2, vm.d dVar) {
        b bVar;
        d dVar2;
        Object f10;
        int i10;
        Iterator it;
        LinkedHashMap linkedHashMap;
        Map map3;
        d dVar3;
        Map map4;
        LinkedHashMap linkedHashMap2;
        Iterator it2;
        String str;
        PackageItemModel packageItemModel;
        Map map5;
        Iterator it3;
        String str2;
        d dVar4;
        PackageItemModel packageItemModel2;
        if (dVar instanceof b) {
            bVar = (b) dVar;
            int i11 = bVar.f18270y;
            if ((i11 & Integer.MIN_VALUE) != 0) {
                bVar.f18270y = i11 - Integer.MIN_VALUE;
                dVar2 = this;
                Object obj = bVar.f18268w;
                f10 = wm.d.f();
                i10 = bVar.f18270y;
                int i12 = 2;
                if (i10 != 0) {
                    y.b(obj);
                    LinkedHashMap linkedHashMap3 = new LinkedHashMap();
                    it = map2.entrySet().iterator();
                    linkedHashMap = linkedHashMap3;
                    map3 = map;
                    if (it.hasNext()) {
                    }
                } else if (i10 == 1) {
                    packageItemModel = (PackageItemModel) bVar.f18266u;
                    str = (String) bVar.f18265t;
                    it2 = (Iterator) bVar.f18264s;
                    ?? r11 = (Map) bVar.f18263r;
                    map4 = (Map) bVar.f18262q;
                    dVar3 = (d) bVar.f18261p;
                    y.b(obj);
                    linkedHashMap2 = r11;
                    String str3 = str;
                    it = it2;
                    linkedHashMap = linkedHashMap2;
                    map3 = map4;
                    d dVar5 = dVar3;
                    PackageItemModel packageItemModel3 = packageItemModel;
                    dVar2 = dVar5;
                    linkedHashMap.put(str3, packageItemModel3);
                    i12 = 2;
                    if (it.hasNext()) {
                    }
                } else if (i10 == 2) {
                    packageItemModel2 = (PackageItemModel) bVar.f18266u;
                    str2 = (String) bVar.f18265t;
                    it3 = (Iterator) bVar.f18264s;
                    ?? r112 = (Map) bVar.f18263r;
                    map5 = (Map) bVar.f18262q;
                    dVar4 = (d) bVar.f18261p;
                    y.b(obj);
                    packageItemModel2.setCloudId(null);
                    linkedHashMap = r112;
                    linkedHashMap.put(str2, packageItemModel2);
                    it = it3;
                    map3 = map5;
                    dVar2 = dVar4;
                    i12 = 2;
                    if (it.hasNext()) {
                    }
                } else {
                    if (i10 != 3) {
                        if (i10 != 4) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        y.b(obj);
                        return n0.f34904a;
                    }
                    TrackSyncItem trackSyncItem = (TrackSyncItem) bVar.f18267v;
                    PackageItemModel packageItemModel4 = (PackageItemModel) bVar.f18266u;
                    String str4 = (String) bVar.f18265t;
                    Iterator it4 = (Iterator) bVar.f18264s;
                    ?? r12 = (Map) bVar.f18263r;
                    Map map6 = (Map) bVar.f18262q;
                    d dVar6 = (d) bVar.f18261p;
                    y.b(obj);
                    LinkedHashMap linkedHashMap4 = r12;
                    packageItemModel4.setCloudId(trackSyncItem.getId());
                    packageItemModel2 = packageItemModel4;
                    str2 = str4;
                    it3 = it4;
                    linkedHashMap = linkedHashMap4;
                    map5 = map6;
                    dVar4 = dVar6;
                    linkedHashMap.put(str2, packageItemModel2);
                    it = it3;
                    map3 = map5;
                    dVar2 = dVar4;
                    i12 = 2;
                    if (it.hasNext()) {
                        Map.Entry entry = (Map.Entry) it.next();
                        String str5 = (String) entry.getKey();
                        PackageItemModel packageItemModel5 = (PackageItemModel) entry.getValue();
                        if (map3.containsKey(str5)) {
                            TrackSyncItem trackSyncItem2 = (TrackSyncItem) map3.get(str5);
                            if (trackSyncItem2 == null) {
                                throw new IllegalStateException("Can't be null here".toString());
                            }
                            if (ig.a.f23217a.e(packageItemModel5, trackSyncItem2)) {
                                if (packageItemModel5.isDeleted()) {
                                    gg.b bVar2 = dVar2.f18251b;
                                    String id2 = trackSyncItem2.getId();
                                    t.f(id2, "getId(...)");
                                    Date modifiedAt = packageItemModel5.getModifiedAt();
                                    bVar.f18261p = dVar2;
                                    bVar.f18262q = map3;
                                    bVar.f18263r = linkedHashMap;
                                    bVar.f18264s = it;
                                    bVar.f18265t = str5;
                                    bVar.f18266u = packageItemModel5;
                                    bVar.f18267v = null;
                                    bVar.f18270y = i12;
                                    if (bVar2.e(id2, modifiedAt, bVar) == f10) {
                                        return f10;
                                    }
                                    map5 = map3;
                                    it3 = it;
                                    str2 = str5;
                                    LinkedHashMap linkedHashMap5 = linkedHashMap;
                                    dVar4 = dVar2;
                                    packageItemModel2 = packageItemModel5;
                                    packageItemModel2.setCloudId(null);
                                    linkedHashMap = linkedHashMap5;
                                    linkedHashMap.put(str2, packageItemModel2);
                                    it = it3;
                                    map3 = map5;
                                    dVar2 = dVar4;
                                } else {
                                    gg.b bVar3 = dVar2.f18251b;
                                    String id3 = trackSyncItem2.getId();
                                    t.f(id3, "getId(...)");
                                    String itemNumber = packageItemModel5.getItemNumber();
                                    String userDescription = packageItemModel5.getUserDescription();
                                    Date createdAt = packageItemModel5.getCreatedAt();
                                    Date modifiedAt2 = packageItemModel5.getModifiedAt();
                                    boolean isSNFItemRead = packageItemModel5.isSNFItemRead();
                                    boolean isFlaggedAsNotMine = packageItemModel5.isFlaggedAsNotMine();
                                    bVar.f18261p = dVar2;
                                    bVar.f18262q = map3;
                                    bVar.f18263r = linkedHashMap;
                                    bVar.f18264s = it;
                                    bVar.f18265t = str5;
                                    bVar.f18266u = packageItemModel5;
                                    bVar.f18267v = trackSyncItem2;
                                    bVar.f18270y = 3;
                                    LinkedHashMap linkedHashMap6 = linkedHashMap;
                                    if (bVar3.d(id3, itemNumber, userDescription, createdAt, modifiedAt2, isSNFItemRead, isFlaggedAsNotMine, bVar) == f10) {
                                        return f10;
                                    }
                                    map6 = map3;
                                    dVar6 = dVar2;
                                    it4 = it;
                                    trackSyncItem = trackSyncItem2;
                                    packageItemModel4 = packageItemModel5;
                                    str4 = str5;
                                    linkedHashMap4 = linkedHashMap6;
                                    packageItemModel4.setCloudId(trackSyncItem.getId());
                                    packageItemModel2 = packageItemModel4;
                                    str2 = str4;
                                    it3 = it4;
                                    linkedHashMap = linkedHashMap4;
                                    map5 = map6;
                                    dVar4 = dVar6;
                                    linkedHashMap.put(str2, packageItemModel2);
                                    it = it3;
                                    map3 = map5;
                                    dVar2 = dVar4;
                                }
                            }
                        } else if (packageItemModel5.isDeleted()) {
                            packageItemModel5.setCloudId(null);
                            linkedHashMap.put(str5, packageItemModel5);
                        } else {
                            gg.b bVar4 = dVar2.f18251b;
                            bVar.f18261p = dVar2;
                            bVar.f18262q = map3;
                            bVar.f18263r = linkedHashMap;
                            bVar.f18264s = it;
                            bVar.f18265t = str5;
                            bVar.f18266u = packageItemModel5;
                            bVar.f18267v = null;
                            bVar.f18270y = 1;
                            if (bVar4.a(packageItemModel5, bVar) == f10) {
                                return f10;
                            }
                            map4 = map3;
                            it2 = it;
                            str = str5;
                            linkedHashMap2 = linkedHashMap;
                            dVar3 = dVar2;
                            packageItemModel = packageItemModel5;
                            String str32 = str;
                            it = it2;
                            linkedHashMap = linkedHashMap2;
                            map3 = map4;
                            d dVar52 = dVar3;
                            PackageItemModel packageItemModel32 = packageItemModel;
                            dVar2 = dVar52;
                            linkedHashMap.put(str32, packageItemModel32);
                        }
                        i12 = 2;
                        if (it.hasNext()) {
                            LinkedHashMap linkedHashMap7 = linkedHashMap;
                            ArrayList arrayList = new ArrayList(linkedHashMap7.size());
                            Iterator it5 = linkedHashMap7.entrySet().iterator();
                            while (it5.hasNext()) {
                                arrayList.add(eg.c.f17056a.a((PackageItemModel) ((Map.Entry) it5.next()).getValue()));
                            }
                            eg.a aVar = dVar2.f18250a;
                            bVar.f18261p = null;
                            bVar.f18262q = null;
                            bVar.f18263r = null;
                            bVar.f18264s = null;
                            bVar.f18265t = null;
                            bVar.f18266u = null;
                            bVar.f18267v = null;
                            bVar.f18270y = 4;
                            if (aVar.a(arrayList, bVar) == f10) {
                                return f10;
                            }
                            return n0.f34904a;
                        }
                    }
                }
            }
        }
        dVar2 = this;
        bVar = new b(dVar);
        Object obj2 = bVar.f18268w;
        f10 = wm.d.f();
        i10 = bVar.f18270y;
        int i122 = 2;
        if (i10 != 0) {
        }
    }
}
