package leigh.conflux;

import java.io.Serializable;
import java.util.Objects;
import java.util.UUID;

/**
 * This class implements a record pointer. The pointer stores a reference from a source record to a destination record,
 * such that the destination record can be modified over time. The pointer is said to have a source, for the purpose
 * that the pointer may be deleted when that source record is deleted.
 *
 * @author Alex Leigh
 */
public class RecordPointer implements Serializable {
    private static final long serialVersionUID = 1L;
    private final UUID srcRecordId;
    private UUID dstRecordId;

    public RecordPointer(UUID srcRecordId, UUID dstRecordId) {
        this.srcRecordId = srcRecordId;
        this.dstRecordId = dstRecordId;
    }

    public UUID getSrcRecordId() {
        return srcRecordId;
    }

    public UUID getDstRecordId() {
        return dstRecordId;
    }

    public void setDstRecordId(UUID dstRecordId) {
        this.dstRecordId = dstRecordId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RecordPointer that = (RecordPointer) o;
        return Objects.equals(srcRecordId, that.srcRecordId) && Objects.equals(dstRecordId, that.dstRecordId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(srcRecordId, dstRecordId);
    }

    @Override
    public String toString() {
        return "RecordPointer{" +
                "srcRecordId=" + srcRecordId +
                ", dstRecordId=" + dstRecordId +
                '}';
    }
}
