import { useEffect, useCallback } from 'react';
import { useProcessHandler } from './actionHandler/useProcessHandler';

export function useMachineActions() {
    const { handleProcess } = useProcessHandler();

    const handleProcessAction = useCallback((action: MachineAction, materialId: string) => {
        handleProcess(action, materialId);
    }, [handleProcess]);

    const handleMachineAction = useCallback((action: MachineAction, materialId: string) => {
        if (!action) return;

        switch (action.actionType) {
            case 'process':
                handleProcessAction(action, materialId);
                break;
            default:
                console.warn(`Unknown machine action type: ${action.actionType}`);
        }
    }, [handleProcessAction]);

    const cleanup = useCallback(() => {
    }, []);

    useEffect(() => {
        return () => {
            cleanup();
        };
    }, [cleanup]);

    return {
        handleMachineAction,
        cleanup,
    };
}