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

function useAssetResponseHandler() {
    const { assetStore } = useSceneContext();
    const { addAsset, updateAsset, removeAsset } = assetStore();

    const addAssetToScene = useCallback(
        (asset: Asset, callback?: () => void) => {
            addAsset(asset);

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

    const updateAssetInScene = useCallback(
        (asset: Asset, callback?: () => void) => {
            updateAsset(asset.modelUuid, asset);

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

    const removeAssetFromScene = useCallback(
        (modelUuid: string, callback?: () => void) => {
            removeAsset(modelUuid);

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

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

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

    const pasteAssetToScene = useCallback((asset: Asset, callback?: () => void) => {
        console.log("Pasting asset: ", asset);

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

    return {
        addAssetToScene,
        updateAssetInScene,
        removeAssetFromScene,
        duplicateAssetInScene,
        pasteAssetToScene,
    };
}

export default useAssetResponseHandler;
