package com.bytedance.hybrid.pia.bridge.protocol;

import X.2HN;
import X.2te;
import X.2th;
import X.7AW;
import X.M12;
import com.bytedance.covode.number.Covode;
import com.bytedance.hybrid.pia.bridge.protocol.Callback;
import com.google.gson.Gson;
import com.google.gson.a.c;
import java.util.Objects;
import kotlin.h.b.n;

public final class ProtocolMessage {
    public static final Companion Companion = new Companion((2HN) null);
    public static final Gson gson = new Gson();
    @c(LIZ = "data")
    public final String data;
    @c(LIZ = "id")
    public final Integer id;
    @c(LIZ = "name")
    public final String name;
    @c(LIZ = "status")
    public final Callback.Status status;
    @c(LIZ = "type")
    public final Type type;
    @c(LIZ = "version")
    public final Integer version;

    public enum Type {
        Invocation,
        Callback
    }

    public static /* synthetic */ ProtocolMessage copy$default(ProtocolMessage protocolMessage, Type type2, Integer num, String str, String str2, Integer num2, Callback.Status status2, int i, Object obj) {
        if ((i & 1) != 0) {
            type2 = protocolMessage.type;
        }
        if ((i & 2) != 0) {
            num = protocolMessage.id;
        }
        if ((i & 4) != 0) {
            str = protocolMessage.data;
        }
        if ((i & 8) != 0) {
            str2 = protocolMessage.name;
        }
        if ((i & 16) != 0) {
            num2 = protocolMessage.version;
        }
        if ((i & 32) != 0) {
            status2 = protocolMessage.status;
        }
        return protocolMessage.copy(type2, num, str, str2, num2, status2);
    }

    private Object[] getObjects() {
        return new Object[]{this.type, this.id, this.data, this.name, this.version, this.status};
    }

    public final ProtocolMessage copy(Type type2, Integer num, String str, String str2, Integer num2, Callback.Status status2) {
        return new ProtocolMessage(type2, num, str, str2, num2, status2);
    }

    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof ProtocolMessage)) {
            return false;
        }
        return M12.LIZ(((ProtocolMessage) obj).getObjects(), getObjects());
    }

    public final int hashCode() {
        return Objects.hash(getObjects());
    }

    public final String toString() {
        return M12.LIZ("ProtocolMessage:%s,%s,%s,%s,%s,%s", getObjects());
    }

    public static final class Companion {

        public final /* synthetic */ class WhenMappings {
            public static final /* synthetic */ int[] $EnumSwitchMapping$0;

            static {
                Covode.recordClassIndex(27671);
                int[] iArr = new int[Type.values().length];
                $EnumSwitchMapping$0 = iArr;
                iArr[Type.Invocation.ordinal()] = 1;
                iArr[Type.Callback.ordinal()] = 2;
            }
        }

        static {
            Covode.recordClassIndex(27670);
        }

        public Companion() {
        }

        public /* synthetic */ Companion(2HN r1) {
            this();
        }

        public final ProtocolMessage createFromWebRawMessage(String str) {
            Object obj;
            Type type;
            M12.LIZ((Object) str);
            try {
                obj = (ProtocolMessage) ProtocolMessage.gson.LIZ(str, ProtocolMessage.class);
                2te.constructor-impl(obj);
            } catch (Throwable th) {
                obj = 2th.LIZ(th);
                2te.constructor-impl(obj);
            }
            if (2te.isFailure-impl(obj)) {
                obj = null;
            }
            ProtocolMessage protocolMessage = (ProtocolMessage) obj;
            if (protocolMessage == null || (type = protocolMessage.getType()) == null) {
                return null;
            }
            int i = WhenMappings.$EnumSwitchMapping$0[type.ordinal()];
            if (i != 1) {
                if (i != 2) {
                    throw new 7AW();
                } else if (protocolMessage.getId() == null || protocolMessage.getId().intValue() >= 0 || protocolMessage.getStatus() == null) {
                    return null;
                } else {
                    return protocolMessage;
                }
            } else if (protocolMessage.getId() == null || protocolMessage.getId().intValue() < 0 || protocolMessage.getName() == null || protocolMessage.getName().length() == 0 || protocolMessage.getVersion() == null || protocolMessage.getVersion().intValue() < 0) {
                return null;
            } else {
                return protocolMessage;
            }
        }

        public final ProtocolMessage createCallback(int i, Callback.Status status, String str) {
            Callback.Status status2 = status;
            M12.LIZ((Object) status2);
            if (i <= 0) {
                return null;
            }
            return new ProtocolMessage(Type.Callback, Integer.valueOf(i), str, (String) null, (Integer) null, status2);
        }

        public final ProtocolMessage createInvocation(int i, String str, int i2, String str2) {
            String str3 = str;
            M12.LIZ((Object) str3);
            if (i > 0 || str3.length() == 0 || i2 < 0) {
                return null;
            }
            return new ProtocolMessage(Type.Invocation, Integer.valueOf(i), str2, str3, Integer.valueOf(i2), (Callback.Status) null);
        }
    }

    public final String getData() {
        return this.data;
    }

    public final Integer getId() {
        return this.id;
    }

    public final String getName() {
        return this.name;
    }

    public final Callback.Status getStatus() {
        return this.status;
    }

    public final Type getType() {
        return this.type;
    }

    public final Integer getVersion() {
        return this.version;
    }

    public final String encode() {
        String LIZIZ = gson.LIZIZ(this);
        n.LIZ(LIZIZ, "");
        return LIZIZ;
    }

    static {
        Covode.recordClassIndex(27669);
    }

    public ProtocolMessage(Type type2, Integer num, String str, String str2, Integer num2, Callback.Status status2) {
        this.type = type2;
        this.id = num;
        this.data = str;
        this.name = str2;
        this.version = num2;
        this.status = status2;
    }
}
