package com.ss.editor.model.undo.impl;

import com.jme3.light.Light;
import com.jme3.scene.Node;
import com.ss.editor.model.undo.editor.ModelChangeConsumer;
import com.ss.editor.model.undo.impl.AbstractEditorOperation;

import org.jetbrains.annotations.NotNull;

/**
 * The implementation of the {@link AbstractEditorOperation} to add a {@link Light} to a {@link Node}.
 *
 * @author JavaSaBr
 */
public class AddLightOperation extends AbstractEditorOperation<ModelChangeConsumer> {

    /**
     * The new light.
     */
    @NotNull
    private final Light light;

    /**
     * The parent.
     */
    @NotNull
    private final Node parent;

    /**
     * Instantiates a new Add light operation.
     *
     * @param light  the light
     * @param parent the parent
     */
    public AddLightOperation(@NotNull final Light light, @NotNull Node parent) {
        this.light = light;
        this.parent = parent;
    }

    @Override
    protected void redoImpl(@NotNull final ModelChangeConsumer editor) {
        EXECUTOR_MANAGER.addJmeTask(() -> {
            parent.addLight(light);
            EXECUTOR_MANAGER.addFxTask(() -> editor.notifyFxAddedChild(parent, light, -1, true));
        });
    }

    @Override
    protected void undoImpl(@NotNull final ModelChangeConsumer editor) {
        EXECUTOR_MANAGER.addJmeTask(() -> {
            parent.removeLight(light);
            EXECUTOR_MANAGER.addFxTask(() -> editor.notifyFxRemovedChild(parent, light));
        });
    }
}
