package net.ranides.assira.observable;

import net.ranides.assira.events.Event;

public abstract class BeanEvent implements Event {

    private final Object source;
    private final String property;

    protected BeanEvent(Object source, String property) {
        this.source = source;
        this.property = property;
    }

    public Object source() {
        return source;
    }

    public String property() {
        return property;
    }

    public static class Change extends BeanEvent {
        private final Object previous;
        private final Object current;

        protected Change(Object source, String property, Object previous, Object current) {
            super(source, property);
            this.previous = previous;
            this.current = current;
        }

        public Object previous() {
            return previous;
        }

        public Object current() {
            return current;
        }

        @Override
        public String toString() {
            return "Change{" + "source=" + source() + ", property='" + property() + '\'' + ", previous=" + previous() + ", current=" + current() + '}';
        }
    }

    public static Change change(Object source, String property, Object previous, Object current) {
        return new Change(source, property, previous, current);
    }

}
