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

export function useHumanActions() {
    const { handleWorker } = useWorkerHandler();
    const { handleManufacturer } = useManufacturerHandler();

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

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

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

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

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

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

    return {
        handleHumanAction,
        cleanup
    };
}