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

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

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

    return { requestStatus, data };
}