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

import de.accso.flexinale.backoffice.api_contract.event.model.FilmTO;
import de.accso.flexinale.common.api.event.AbstractEvent;
import de.accso.flexinale.common.api.event.Event;
import de.accso.flexinale.common.shared_kernel.DoNotCheckInArchitectureTests;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

public abstract sealed class FilmCRUDEvent extends AbstractEvent implements Event
    permits FilmCreatedEvent, FilmUpdatedEvent, FilmDeletedEvent {

    public enum CRUD { CREATE, UPDATE, DELETE }

    @DoNotCheckInArchitectureTests
    public final FilmTO film;

    protected FilmCRUDEvent(final FilmTO film) {
        this.film = film;
    }

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

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

        final FilmCRUDEvent that = (FilmCRUDEvent) o;

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

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