import { useEffect, useState } from 'react';

import { Farm } from '@/models/farm';
import { Processor } from '@/models/processor';
import { getSupplyChainData } from '../../data/utils';

export const useSupplyChainData = () => {
    const [farms, setFarms] = useState<Farm[]>([]);
    const [processors, setProcessors] = useState<Processor[]>([]);

    useEffect(() => {
        async function fetchData() {
            const { farms, processors } = await getSupplyChainData();
            setFarms(farms);
            setProcessors(processors);
        }

        fetchData();
    }, []);

    return { farms, processors };
};