package net.ranides.assira.io;

import net.ranides.assira.events.Event;

import java.nio.file.Path;

/**
 * This event is sent if some change for this path was observed.
 *
 * We support create, modification and deletion.
 *
 * It can be sent both for directories and files.
 */
public abstract class FileObserverEvent implements Event {

    private final Path path;

    /**
     * Creates new event. Not supposed to be called directly. Please use one of static factory methods.
     *
     * @param path path
     */
    protected FileObserverEvent(Path path) {
        this.path = path;
    }

    /**
     * Returns affected path.
     *
     * @return path
     */
    public Path path() {
        return path;
    }

    /**
     * Creates new CREATE event.
     * @param path path
     * @return event
     */
    public static Create create(Path path) {
        return new Create(path);
    }

    /**
     * Creates new MODIFY event.
     * @param path path
     * @return event
     */
    public static Modify modify(Path path) {
        return new Modify(path);
    }

    /**
     * Creates new DELETE event.
     * @param path path
     * @return event
     */
    public static Delete delete(Path path) {
        return new Delete(path);
    }

    public static Cancel cancel(Path path) {
        return new Cancel(path);
    }

    /**
     * Event: create
     */
    public static class Create extends FileObserverEvent {
        protected Create(Path path) {
            super(path);
        }
    }

    /**
     * Event: modify
     */
    public static class Modify extends FileObserverEvent {
        protected Modify(Path path) {
            super(path);
        }
    }

    /**
     * Event: delete
     */
    public static class Delete extends FileObserverEvent {
        protected Delete(Path path) {
            super(path);
        }
    }

    /**
     * Event: cancel
     */
    public static class Cancel extends FileObserverEvent {
        protected Cancel(Path path) {
            super(path);
        }
    }

}
