package net.ranides.assira.observable;

import lombok.RequiredArgsConstructor;
import net.ranides.assira.events.Event;

import java.util.Collection;

public interface CollectionEvent<T> extends Event {

    Collection<T> collection();

    @RequiredArgsConstructor
    class Remove<T> implements CollectionEvent<T> {
        private final Collection<T> collection;
        private final T value;

        @Override
        public Collection<T> collection() {
            return collection;
        }

        public T value() {
            return value;
        }
    }

    @RequiredArgsConstructor
    class RemoveMany<T> implements CollectionEvent<T> {
        private final Collection<T> collection;
        private final Collection<T> values;

        @Override
        public Collection<T> collection() {
            return collection;
        }

        public Collection<T> values() {
            return values;
        }
    }

    @RequiredArgsConstructor
    class Clear<T> implements CollectionEvent<T> {
        private final Collection<T> collection;

        @Override
        public Collection<T> collection() {
            return collection;
        }
    }

    @RequiredArgsConstructor
    class Set<T> implements CollectionEvent<T> {
        private final Collection<T> collection;
        private final T previous;
        private final T value;

        @Override
        public Collection<T> collection() {
            return collection;
        }

        public T previous() {
            return previous;
        }

        public T value() {
            return value;
        }
    }

    @RequiredArgsConstructor
    class Add<T> implements CollectionEvent<T> {
        private final Collection<T> collection;
        private final T value;

        @Override
        public Collection<T> collection() {
            return collection;
        }

        public T value() {
            return value;
        }
    }

    @RequiredArgsConstructor
    class AddMany<T> implements CollectionEvent<T> {
        private final Collection<T> collection;
        private final Collection<? extends T> values;

        @Override
        public Collection<T> collection() {
            return collection;
        }

        public Collection<? extends T> values() {
            return values;
        }
    }
}
