package com.google.android.datatransport.cct;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import v6.o;

/* JADX INFO: loaded from: classes2.dex */
public final class a implements o {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final String f7718b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final Set f7719c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final a f7720d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final a f7721e;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final String f7722a;

    @Nullable
    private final String apiKey;

    static {
        String strP0 = hb.a.p0("hts/frbslgiggolai.o/0clgbthfra=snpoo", "tp:/ieaeogn.ogepscmvc/o/ac?omtjo_rt3");
        f7718b = strP0;
        String strP02 = hb.a.p0("hts/frbslgigp.ogepscmv/ieo/eaybtho", "tp:/ieaeogn-agolai.o/1frlglgc/aclg");
        String strP03 = hb.a.p0("AzSCki82AwsLzKd5O8zo", "IayckHiZRO1EFl1aGoK");
        f7719c = Collections.unmodifiableSet(new HashSet(Arrays.asList(new t6.c("proto"), new t6.c("json"))));
        f7720d = new a(strP0, null);
        f7721e = new a(strP02, strP03);
    }

    public a(@NonNull String str, @Nullable String str2) {
        this.f7722a = str;
        this.apiKey = str2;
    }

    public static a a(byte[] bArr) {
        String str = new String(bArr, Charset.forName("UTF-8"));
        if (!str.startsWith("1$")) {
            throw new IllegalArgumentException("Version marker missing from extras");
        }
        String[] strArrSplit = str.substring(2).split(Pattern.quote("\\"), 2);
        if (strArrSplit.length != 2) {
            throw new IllegalArgumentException("Extra is not a valid encoded LegacyFlgDestination");
        }
        String str2 = strArrSplit[0];
        if (str2.isEmpty()) {
            throw new IllegalArgumentException("Missing endpoint in CCTDestination extras");
        }
        String str3 = strArrSplit[1];
        if (str3.isEmpty()) {
            str3 = null;
        }
        return new a(str2, str3);
    }

    @Nullable
    public byte[] asByteArray() {
        String str = this.apiKey;
        String str2 = this.f7722a;
        if (str == null && str2 == null) {
            return null;
        }
        Object[] objArr = new Object[4];
        objArr[0] = "1$";
        objArr[1] = str2;
        objArr[2] = "\\";
        if (str == null) {
            str = "";
        }
        objArr[3] = str;
        return String.format("%s%s%s%s", objArr).getBytes(Charset.forName("UTF-8"));
    }

    @Nullable
    public String getAPIKey() {
        return this.apiKey;
    }

    @Override // v6.o, v6.n
    @Nullable
    public byte[] getExtras() {
        return asByteArray();
    }
}
