import { useDataContext } from "../../common/contexts/data_context";
import { useGet } from "../../common/hooks/useGet";
import { StateEntity } from '../domain/entities/state_entity';
import { TownEntity } from "../domain/entities/town_entity";

export const useGetTowns = (stateId: number) => {
    const { statesRepository } = useDataContext();

    const callback = async () =>{
        return await statesRepository?.getTowns(stateId) || [];
    }
    const { requestStatus, data, refresh } = useGet<TownEntity[]>(callback);

    return { requestStatus, data, refresh };
}