package f0; import d0.g0.t; import d0.t.h0; import d0.t.n; import d0.z.d.m; import f0.f0.c; import f0.f0.h.f; import f0.w; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; import kotlin.Pair; import okhttp3.Headers; import okhttp3.RequestBody; /* compiled from: Request.kt */ public final class z { public d a; public final w b; /* renamed from: c reason: collision with root package name */ public final String f2785c; public final Headers d; public final RequestBody e; public final Map, Object> f; /* compiled from: Request.kt */ public static class a { public w a; public String b; /* renamed from: c reason: collision with root package name */ public Headers.a f2786c; public RequestBody d; public Map, Object> e; public a() { this.e = new LinkedHashMap(); this.b = "GET"; this.f2786c = new Headers.a(); } public a(z zVar) { m.checkParameterIsNotNull(zVar, "request"); this.e = new LinkedHashMap(); this.a = zVar.b; this.b = zVar.f2785c; this.d = zVar.e; this.e = zVar.f.isEmpty() ? new LinkedHashMap<>() : h0.toMutableMap(zVar.f); this.f2786c = zVar.d.e(); } public z a() { Map map; w wVar = this.a; if (wVar != null) { String str = this.b; Headers c2 = this.f2786c.c(); RequestBody requestBody = this.d; Map, Object> map2 = this.e; byte[] bArr = c.a; m.checkParameterIsNotNull(map2, "$this$toImmutableMap"); if (map2.isEmpty()) { map = h0.emptyMap(); } else { map = Collections.unmodifiableMap(new LinkedHashMap(map2)); m.checkExpressionValueIsNotNull(map, "Collections.unmodifiableMap(LinkedHashMap(this))"); } return new z(wVar, str, c2, requestBody, map); } throw new IllegalStateException("url == null".toString()); } public a b(String str, String str2) { m.checkParameterIsNotNull(str, "name"); m.checkParameterIsNotNull(str2, "value"); Headers.a aVar = this.f2786c; Objects.requireNonNull(aVar); m.checkParameterIsNotNull(str, "name"); m.checkParameterIsNotNull(str2, "value"); Headers.b bVar = Headers.i; bVar.a(str); bVar.b(str2, str); aVar.d(str); aVar.b(str, str2); return this; } public a c(String str, RequestBody requestBody) { m.checkParameterIsNotNull(str, "method"); boolean z2 = false; if (str.length() > 0) { if (requestBody == null) { m.checkParameterIsNotNull(str, "method"); if (m.areEqual(str, "POST") || m.areEqual(str, "PUT") || m.areEqual(str, "PATCH") || m.areEqual(str, "PROPPATCH") || m.areEqual(str, "REPORT")) { z2 = true; } if (!(!z2)) { throw new IllegalArgumentException(c.d.b.a.a.u("method ", str, " must have a request body.").toString()); } } else if (!f.a(str)) { throw new IllegalArgumentException(c.d.b.a.a.u("method ", str, " must not have a request body.").toString()); } this.b = str; this.d = requestBody; return this; } throw new IllegalArgumentException("method.isEmpty() == true".toString()); } public a d(String str) { m.checkParameterIsNotNull(str, "name"); this.f2786c.d(str); return this; } public a e(Class cls, T t) { m.checkParameterIsNotNull(cls, "type"); if (t == null) { this.e.remove(cls); } else { if (this.e.isEmpty()) { this.e = new LinkedHashMap(); } Map, Object> map = this.e; Object cast = cls.cast(t); if (cast == null) { m.throwNpe(); } map.put(cls, cast); } return this; } public a f(String str) { m.checkParameterIsNotNull(str, "url"); if (t.startsWith(str, "ws:", true)) { StringBuilder L = c.d.b.a.a.L("http:"); String substring = str.substring(3); m.checkExpressionValueIsNotNull(substring, "(this as java.lang.String).substring(startIndex)"); L.append(substring); str = L.toString(); } else if (t.startsWith(str, "wss:", true)) { StringBuilder L2 = c.d.b.a.a.L("https:"); String substring2 = str.substring(4); m.checkExpressionValueIsNotNull(substring2, "(this as java.lang.String).substring(startIndex)"); L2.append(substring2); str = L2.toString(); } m.checkParameterIsNotNull(str, "$this$toHttpUrl"); w.a aVar = new w.a(); aVar.e(null, str); g(aVar.b()); return this; } public a g(w wVar) { m.checkParameterIsNotNull(wVar, "url"); this.a = wVar; return this; } } public z(w wVar, String str, Headers headers, RequestBody requestBody, Map, ? extends Object> map) { m.checkParameterIsNotNull(wVar, "url"); m.checkParameterIsNotNull(str, "method"); m.checkParameterIsNotNull(headers, "headers"); m.checkParameterIsNotNull(map, "tags"); this.b = wVar; this.f2785c = str; this.d = headers; this.e = requestBody; this.f = map; } public final d a() { d dVar = this.a; if (dVar != null) { return dVar; } d b = d.a.b(this.d); this.a = b; return b; } public final String b(String str) { m.checkParameterIsNotNull(str, "name"); return this.d.c(str); } public String toString() { StringBuilder L = c.d.b.a.a.L("Request{method="); L.append(this.f2785c); L.append(", url="); L.append(this.b); if (this.d.size() != 0) { L.append(", headers=["); int i = 0; for (Pair pair : this.d) { int i2 = i + 1; if (i < 0) { n.throwIndexOverflow(); } Pair pair2 = pair; String str = (String) pair2.component1(); String str2 = (String) pair2.component2(); if (i > 0) { L.append(", "); } L.append(str); L.append(':'); L.append(str2); i = i2; } L.append(']'); } if (!this.f.isEmpty()) { L.append(", tags="); L.append(this.f); } L.append('}'); String sb = L.toString(); m.checkExpressionValueIsNotNull(sb, "StringBuilder().apply(builderAction).toString()"); return sb; } }