import { api } from "../trpc";

export function useCourse() {
    const utils = api.useUtils();
    return {
        // Queries
        findMany: api.course.findMany.useQuery,
        findFirst: api.course.findFirst.useQuery,
        findManyWithCursor: api.course.findManyWithCursor.useQuery,

        // Mutations
        create: api.course.create.useMutation({
            onSuccess: () => {
                utils.course.invalidate()
                utils.course.findMany.invalidate();
                utils.course.findManyWithCursor.invalidate();
                utils.course.findManyWithPagination.invalidate()
            },
        }),
        update: api.course.update.useMutation({
            onSuccess: () => {
                utils.course.findMany.invalidate();
                utils.course.findManyWithCursor.invalidate();
                utils.course.findManyWithPagination.invalidate()
            },
        }),
        createMany: api.course.createMany.useMutation({
            onSuccess: () => {
                utils.course.findMany.invalidate();
                utils.course.findManyWithCursor.invalidate();
                utils.course.findManyWithPagination.invalidate()
            },
        }),
        deleteMany: api.course.deleteMany.useMutation({
            onSuccess: () => {
                utils.course.findMany.invalidate();
                utils.course.findManyWithCursor.invalidate();
                utils.course.findManyWithPagination.invalidate()
            },
        }),
        softDeleteByIds: api.course.softDeleteByIds.useMutation({
            onSuccess: () => {
                utils.course.findMany.invalidate();
                utils.course.findManyWithCursor.invalidate();
                utils.course.findManyWithPagination.invalidate()
            },
        }),
        updateOrder: api.course.updateOrder.useMutation({
            onSuccess: () => {
                utils.course.findMany.invalidate();
                utils.course.findManyWithCursor.invalidate();
                utils.course.findManyWithPagination.invalidate()
            },
        })
    };
}