package okhttp3.internal.http;

import S4.w;
import java.net.ProtocolException;
import kotlin.jvm.internal.o;
import okhttp3.Protocol;

/* JADX INFO: loaded from: classes3.dex */
public final class StatusLine {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final Companion f22398d = new Companion(0);

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final int f22400b;

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

    public static final class Companion {
        public /* synthetic */ Companion(int i6) {
            this();
        }

        public static StatusLine a(String statusLine) throws ProtocolException {
            Protocol protocol;
            int i6;
            String strSubstring;
            o.h(statusLine, "statusLine");
            if (w.A0(statusLine, "HTTP/1.", false)) {
                i6 = 9;
                if (statusLine.length() < 9 || statusLine.charAt(8) != ' ') {
                    throw new ProtocolException("Unexpected status line: ".concat(statusLine));
                }
                int iCharAt = statusLine.charAt(7) - '0';
                if (iCharAt == 0) {
                    protocol = Protocol.HTTP_1_0;
                } else {
                    if (iCharAt != 1) {
                        throw new ProtocolException("Unexpected status line: ".concat(statusLine));
                    }
                    protocol = Protocol.HTTP_1_1;
                }
            } else {
                if (!w.A0(statusLine, "ICY ", false)) {
                    throw new ProtocolException("Unexpected status line: ".concat(statusLine));
                }
                protocol = Protocol.HTTP_1_0;
                i6 = 4;
            }
            int i7 = i6 + 3;
            if (statusLine.length() < i7) {
                throw new ProtocolException("Unexpected status line: ".concat(statusLine));
            }
            try {
                String strSubstring2 = statusLine.substring(i6, i7);
                o.g(strSubstring2, "this as java.lang.String…ing(startIndex, endIndex)");
                int i8 = Integer.parseInt(strSubstring2);
                if (statusLine.length() <= i7) {
                    strSubstring = "";
                } else {
                    if (statusLine.charAt(i7) != ' ') {
                        throw new ProtocolException("Unexpected status line: ".concat(statusLine));
                    }
                    strSubstring = statusLine.substring(i6 + 4);
                    o.g(strSubstring, "this as java.lang.String).substring(startIndex)");
                }
                return new StatusLine(protocol, i8, strSubstring);
            } catch (NumberFormatException unused) {
                throw new ProtocolException("Unexpected status line: ".concat(statusLine));
            }
        }

        private Companion() {
        }
    }

    public StatusLine(Protocol protocol, int i6, String message) {
        o.h(protocol, "protocol");
        o.h(message, "message");
        this.f22399a = protocol;
        this.f22400b = i6;
        this.f22401c = message;
    }

    public final String toString() {
        StringBuilder sb = new StringBuilder();
        if (this.f22399a == Protocol.HTTP_1_0) {
            sb.append("HTTP/1.0");
        } else {
            sb.append("HTTP/1.1");
        }
        sb.append(' ');
        sb.append(this.f22400b);
        sb.append(' ');
        sb.append(this.f22401c);
        String string = sb.toString();
        o.g(string, "StringBuilder().apply(builderAction).toString()");
        return string;
    }
}
