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.OnlineKontingentTO;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

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

    @DoNotCheckInArchitectureTests
    public OnlineKontingentTO onlineKontingent;

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

    public OnlineKontingentChangedEvent(final EventContext predecessorEventContext, final OnlineKontingentTO onlineKontingent) {
        super(predecessorEventContext);
        this.onlineKontingent = onlineKontingent;
    }

    public OnlineKontingentChangedEvent(final OnlineKontingentTO onlineKontingent) {
        this.onlineKontingent = onlineKontingent;
    }

    @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 OnlineKontingentChangedEvent that = (OnlineKontingentChangedEvent) o;

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

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