package de.accso.flexinale.ticketing.api_contract.event;

import com.fasterxml.jackson.annotation.JsonGetter;
import de.accso.flexinale.common.api.event.AbstractEvent;
import de.accso.flexinale.common.api.event.Event;
import de.accso.flexinale.common.api.event.EventContext;
import de.accso.flexinale.common.shared_kernel.DoNotCheckInArchitectureTests;
import de.accso.flexinale.common.shared_kernel.Versionable;
import de.accso.flexinale.ticketing.api_contract.event.model.TicketTO;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

@SuppressWarnings({"unused", "CanBeFinal"})
public class TicketGekauftEvent extends AbstractEvent implements Event {
    private static Version version = Versionable.initialVersion().inc();

    @DoNotCheckInArchitectureTests
    public TicketTO ticket;

    private TicketGekauftEvent() {} // needed for (de)serialization via Jackson

    public TicketGekauftEvent(final EventContext predecessorEventContext, final TicketTO ticket) {
        super(predecessorEventContext);
        this.ticket = ticket;
    }

    public TicketGekauftEvent(final TicketTO ticket) {
        this.ticket = ticket;
    }

    @Override
    @JsonGetter("version") // needed as otherwise the static field version is not (de)serialized
    public Version version() {
        return version;
    }

    @Override
    public boolean equals(final Object o) {
        if (this == o) {return true;}

        if (o == null || getClass() != o.getClass()) {return false;}

        final TicketGekauftEvent that = (TicketGekauftEvent) o;

        return new EqualsBuilder().appendSuper(super.equals(o))
                .append(this.version(), that.version())
                .append(ticket, that.ticket).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37)
                .appendSuper(super.hashCode()).append(ticket)
                .append(this.version())
                .toHashCode();
    }
}
