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

function useWallAssetResponseHandler() {
    const { wallAssetStore } = useSceneContext();
    const { addWallAsset, updateWallAsset, removeWallAsset } = wallAssetStore();

    const addWallAssetToScene = useCallback(
        (asset: WallAsset, callback?: () => void) => {
            addWallAsset(asset);

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

    const updateWallAssetInScene = useCallback(
        (asset: WallAsset, callback?: () => void) => {
            updateWallAsset(asset.modelUuid, asset);

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

    const removeWallAssetFromScene = useCallback(
        (modelUuid: string, callback?: () => void) => {
            removeWallAsset(modelUuid);

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

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

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

    const pasteAssetWallToScene = useCallback((asset: WallAsset, callback?: () => void) => {
        console.log("Pasting wallAsset: ", asset);

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

    return {
        addWallAssetToScene,
        updateWallAssetInScene,
        removeWallAssetFromScene,
        duplicateWallAssetInScene,
        pasteAssetWallToScene,
    };
}

export default useWallAssetResponseHandler;
