package eu.bellettini.eventstore4j.data;

import org.json.JSONObject;

import java.time.Instant;
import java.util.UUID;

public final class ReadEvent {
    private final UUID id;

    private final String aggregateId;

    private final long aggregateVersion;

    private final Instant createdAt;

    private final String source;

    private final String type;

    private final int typeVersion;

    private final JSONObject payload;

    private final Instant receivedAt;

    public ReadEvent(UUID id, String aggregateId, long aggregateVersion, Instant createdAt, String source, String type,
                     int typeVersion, JSONObject payload, Instant receivedAt) {
        this.id = id;
        this.aggregateId = aggregateId;
        this.aggregateVersion = aggregateVersion;
        this.createdAt = createdAt;
        this.source = source;
        this.type = type;
        this.typeVersion = typeVersion;
        this.payload = payload;
        this.receivedAt = receivedAt;
    }

    public ReadEvent(UUID id, String aggregateId, long aggregateVersion, Instant createdAt, String source, String type,
                     int typeVersion, String payload, Instant receivedAt) {
        this(id, aggregateId, aggregateVersion, createdAt, source, type, typeVersion, new JSONObject(payload), receivedAt);
    }

    public UUID getId() {
        return id;
    }

    public String getAggregateId() {
        return aggregateId;
    }

    public long getAggregateVersion() {
        return aggregateVersion;
    }

    public Instant getCreatedAt() {
        return createdAt;
    }

    public String getSource() {
        return source;
    }

    public String getType() {
        return type;
    }

    public int getTypeVersion() {
        return typeVersion;
    }

    public JSONObject getPayload() {
        return payload;
    }

    public Instant getReceivedAt() {
        return receivedAt;
    }

    public WriteEvent toWriteEvent() {
        return new WriteEvent(getId(), getCreatedAt(), getSource(), getType(), getTypeVersion(), getPayload());
    }
}

@@ -2077,11 +2077,1362 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public boolean equals(Object o) %7B%0A        if (this == o) return true;%0A        if (o == null %7C%7C getClass() != o.getClass()) return false;%0A%0A        ReadEvent readEvent = (ReadEvent) o;%0A%0A        if (aggregateVersion != readEvent.aggregateVersion) return false;%0A        if (typeVersion != readEvent.typeVersion) return false;%0A        if (!id.equals(readEvent.id)) return false;%0A        if (!aggregateId.equals(readEvent.aggregateId)) return false;%0A        if (!createdAt.equals(readEvent.createdAt)) return false;%0A        if (!source.equals(readEvent.source)) return false;%0A        if (!type.equals(readEvent.type)) return false;%0A        if (!payload.toString().equals(readEvent.payload.toString())) return false;%0A        return receivedAt.equals(readEvent.receivedAt);%0A%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        int result = id.hashCode();%0A        result = 31 * result + aggregateId.hashCode();%0A        result = 31 * result + (int) (aggregateVersion %5E (aggregateVersion %3E%3E%3E 32));%0A        result = 31 * result + createdAt.hashCode();%0A        result = 31 * result + source.hashCode();%0A        result = 31 * result + type.hashCode();%0A        result = 31 * result + typeVersion;%0A        result = 31 * result + payload.toString().hashCode();%0A        result = 31 * result + receivedAt.hashCode();%0A        return result;%0A    %7D
 %0A%7D%0A

Implement equals and hashCode