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

export function useHumanActions() {
    const { handleWorker } = useWorkerHandler();
    const { handleAssembly } = useAssemblyHandler();

    const handleWorkerAction = useCallback((action: HumanAction, materialId: string) => {
        handleWorker(action, materialId);
    }, [handleWorker]);

    const handleAssemblyAction = useCallback((action: HumanAction, materialId: string) => {
        handleAssembly(action, materialId);
    }, [handleAssembly]);

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

        switch (action.actionType) {
            case 'worker':
                handleWorkerAction(action, materialId);
                break;
            case 'assembly':
                handleAssemblyAction(action, materialId);
                break;
            default:
                console.warn(`Unknown Human action type: ${action.actionType}`);
        }
    }, [handleWorkerAction, handleAssemblyAction]);

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

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

    return {
        handleHumanAction,
        cleanup
    };
}