import { Injectable } from '@nestjs/common';
import { TrpcService } from '@server/trpc/trpc.service';
import { Prisma, UpdateOrderSchema } from '@nice/common';
import { LectureService } from './lecture.service';
import { z, ZodType } from 'zod';
const LectureCreateArgsSchema: ZodType<Prisma.LectureCreateArgs> = z.any()
const LectureCreateManyInputSchema: ZodType<Prisma.LectureCreateManyInput> = z.any()
const LectureDeleteManyArgsSchema: ZodType<Prisma.LectureDeleteManyArgs> = z.any()
const LectureFindManyArgsSchema: ZodType<Prisma.LectureFindManyArgs> = z.any()
const LectureFindFirstArgsSchema: ZodType<Prisma.LectureFindFirstArgs> = z.any()
const LectureWhereInputSchema: ZodType<Prisma.LectureWhereInput> = z.any()
const LectureSelectSchema: ZodType<Prisma.LectureSelect> = z.any()

@Injectable()
export class LectureRouter {
    constructor(
        private readonly trpc: TrpcService,
        private readonly lectureService: LectureService,
    ) { }
    router = this.trpc.router({
        create: this.trpc.protectProcedure
            .input(LectureCreateArgsSchema)
            .mutation(async ({ ctx, input }) => {
                const { staff } = ctx;
                return await this.lectureService.create(input, {staff});
            }),
        createMany: this.trpc.protectProcedure.input(z.array(LectureCreateManyInputSchema))
            .mutation(async ({ ctx, input }) => {
                const { staff } = ctx;

                return await this.lectureService.createMany({ data: input }, staff);
            }),
        deleteMany: this.trpc.procedure
            .input(LectureDeleteManyArgsSchema)
            .mutation(async ({ input }) => {
                return await this.lectureService.deleteMany(input);
            }),
        findFirst: this.trpc.procedure
            .input(LectureFindFirstArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword
            .query(async ({ input }) => {
                return await this.lectureService.findFirst(input);
            }),
        softDeleteByIds: this.trpc.protectProcedure
            .input(z.object({ ids: z.array(z.string()) })) // expect input according to the schema
            .mutation(async ({ input }) => {
                return this.lectureService.softDeleteByIds(input.ids);
            }),
        updateOrder: this.trpc.protectProcedure
            .input(UpdateOrderSchema)
            .mutation(async ({ input }) => {
                return this.lectureService.updateOrder(input);
            }),
        findMany: this.trpc.procedure
            .input(LectureFindManyArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword
            .query(async ({ input }) => {
                return await this.lectureService.findMany(input);
            }),
        findManyWithCursor: this.trpc.protectProcedure
            .input(z.object({
                cursor: z.any().nullish(),
                take: z.number().nullish(),
                where: LectureWhereInputSchema.nullish(),
                select: LectureSelectSchema.nullish()
            }))
            .query(async ({ ctx, input }) => {
                const { staff } = ctx;
                return await this.lectureService.findManyWithCursor(input);
            }),
    });
}
