import { useCallback } from "react";
import { useSceneContext } from "../../scene/sceneContext";

function useWallResponseHandler() {
    const { wallStore } = useSceneContext();
    const { addWall, updateWall, removeWall } = wallStore();

    const addWallToScene = useCallback(
        (wall: Wall, callback?: () => void) => {
            addWall(wall);

            if (callback) callback();
        },
        [addWall]
    );

    const updateWallInScene = useCallback(
        (wall: Wall, callback?: () => void) => {
            updateWall(wall.wallUuid, wall);

            if (callback) callback();
        },
        [updateWall]
    );

    const removeWallFromScene = useCallback(
        (modelUuid: string, callback?: () => void) => {
            removeWall(modelUuid);

            if (callback) callback();
        },
        [removeWall]
    );

    const duplicateWallInScene = useCallback((modelUuid: string, callback?: () => void) => {
        console.log("Duplicating wall: ", modelUuid);

        if (callback) callback();
    }, []);

    const pasteAssetWallToScene = useCallback((wall: Wall, callback?: () => void) => {
        console.log("Pasting wall: ", wall);

        if (callback) callback();
    }, []);

    return {
        addWallToScene,
        updateWallInScene,
        removeWallFromScene,
        duplicateWallInScene,
        pasteAssetWallToScene,
    };
}

export default useWallResponseHandler;
