package com.snapchat.kit.sdk.core.metrics.b;

import X.C1986Pol;
import android.util.Base64;
import com.bytedance.covode.number.Covode;
import com.google.gson.Gson;
import com.google.gson.n;
import com.squareup.wire.Message;
import com.squareup.wire.ProtoAdapter;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

public final class a {
    public static final Type LIZ = new com.google.gson.b.a<List<C1986Pol<String>>>() {
        static {
            Covode.recordClassIndex(47438);
        }
    }.type;
    public final Gson LIZIZ;

    static {
        Covode.recordClassIndex(47437);
    }

    public a(Gson gson) {
        this.LIZIZ = gson;
    }

    public final <T extends Message> String LIZ(List<C1986Pol<T>> list) {
        try {
            return this.LIZIZ.LIZIZ(LIZIZ(list), LIZ);
        } catch (n unused) {
            return null;
        }
    }

    public static <T extends Message> List<C1986Pol<String>> LIZIZ(List<C1986Pol<T>> list) {
        ArrayList arrayList = new ArrayList(list.size());
        for (C1986Pol next : list) {
            try {
                arrayList.add(new C1986Pol(Base64.encodeToString(((Message) next.LIZIZ).encode(), 0), next.LIZ));
            } catch (Exception unused) {
            }
        }
        return arrayList;
    }

    public final <T extends Message> List<C1986Pol<T>> LIZ(ProtoAdapter<T> protoAdapter, String str) {
        try {
            List list = (List) this.LIZIZ.LIZ(str, LIZ);
            if (list == null) {
                return null;
            }
            return LIZ(protoAdapter, (List<C1986Pol<String>>) list);
        } catch (n unused) {
            return null;
        }
    }

    public static <T extends Message> List<C1986Pol<T>> LIZ(ProtoAdapter<T> protoAdapter, List<C1986Pol<String>> list) {
        ArrayList arrayList = new ArrayList(list.size());
        for (C1986Pol next : list) {
            String str = (String) next.LIZIZ;
            if (str != null) {
                try {
                    arrayList.add(new C1986Pol((Message) protoAdapter.decode(Base64.decode(str, 0)), next.LIZ));
                } catch (Exception unused) {
                }
            }
        }
        return arrayList;
    }
}
