package de.accso.flexinale.common.api.event;

import de.accso.flexinale.common.api.event.AbstractEvent;
import de.accso.flexinale.common.api.event.Event;
import de.accso.flexinale.common.shared_kernel.Versionable;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

public final class EventTestdata {

    public static final class MyNumberEvent extends AbstractEvent {
        public final Integer value1;
        public final Integer value2;

        public final Version version = Versionable.initialVersion();

        public MyNumberEvent(final Integer value1, final Integer value2) {
            this.value1 = value1;
            this.value2 = value2;
        }

        public MyNumberEvent(final Event predecessorEvent, final Integer value1, final Integer value2) {
            super(predecessorEvent);
            this.value1 = value1;
            this.value2 = value2;
        }

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

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

            final MyNumberEvent that = (MyNumberEvent) o;

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

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

        @Override
        public Version version() {
            return version;
        }
    }

    public static final class MyTextEvent extends AbstractEvent {
        public final String text1;
        public final String text2;

        public final Version version = Versionable.initialVersion();

        public MyTextEvent(final String text1, final String text2) {
            this.text1 = text1;
            this.text2 = text2;
        }

        public MyTextEvent(final Id correlationId, final String text1, final String text2) {
            super(correlationId);
            this.text1 = text1;
            this.text2 = text2;
        }

        public MyTextEvent(final Event predecessorEvent, final String text1, final String text2) {
            super(predecessorEvent);
            this.text1 = text1;
            this.text2 = text2;
        }

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

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

            final MyTextEvent that = (MyTextEvent) o;

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

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

        @Override
        public Version version() {
            return version;
        }
    }

    public static final class MyMixedEvent extends AbstractEvent {
        public final String text;
        public final Integer number;

        public final Version version = Versionable.initialVersion();

        public MyMixedEvent(final String text, final Integer number) {
            this.text = text;
            this.number = number;
        }

        public MyMixedEvent(final Event predecessorEvent, final String text, final Integer number) {
            super(predecessorEvent);
            this.text = text;
            this.number = number;
        }

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

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

            final MyMixedEvent that = (MyMixedEvent) o;

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

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

        @Override
        public Version version() {
            return version;
        }
    }
}
