const stateResolvers = () => ({
    State: {
        async country(src, arg, { countryDataLoader }) {
            // If it's already has been updated
            if (src?.country?.name) {
                return src.country;
            }
            return countryDataLoader.load(src.country.toString());
        },
        async cities(src, args, { cityService }) {
            const criteria = { ...args.criteria, state: src.id };
            const data = await cityService.getAll({
                ...args,
                criteria,
            });
            const totalCount = await cityService.count(criteria);
            return {
                totalCount,
                data,
            };
        },
    },
    Query: {
        async states(_, args, { stateService }, info) {
            const data = await stateService.getAll(args);
            const totalCount = await stateService.count(args.criteria);
            return {
                totalCount,
                data,
            };
        },
        state(_, { id }, { stateService }) {
            return stateService.get(id);
        },
    },
    Mutation: {
        createState(_, { state }, { stateService }) {
            return stateService.create(state);
        },
        updateState(_, { id, state }, { stateService }) {
            return stateService.update(id, state, false);
        },
        deleteState(_, { id }, { stateService }) {
            return stateService.delete(id);
        },
    },
});export{stateResolvers};