import { z, ZodType } from "zod";
import { ShareCodeService } from "./share-code.service";
import { TrpcService } from "@server/trpc/trpc.service";
import { Injectable } from "@nestjs/common";
import { Prisma } from "@nice/common";
const ShareCodeWhereInputSchema: ZodType<Prisma.ShareCodeWhereInput> = z.any();
@Injectable()
export class ShareCodeRouter {
    constructor(
        private readonly shareCodeService: ShareCodeService,
        private readonly trpc: TrpcService
    ) { }

    router = this.trpc.router({
        generateShareCode: this.trpc.procedure
            .input(z.object({ fileId: z.string(), expiresAt: z.date(), canUseTimes: z.number() }))
            .mutation(async ({ input }) => {
                return this.shareCodeService.generateShareCode(input.fileId, input.expiresAt, input.canUseTimes);
            }),
        validateAndUseCode: this.trpc.procedure
            .input(z.object({ code: z.string() }))
            .mutation(async ({ input }) => {
                return this.shareCodeService.validateAndUseCode(input.code);
            }),
        getShareCodeInfo: this.trpc.procedure
            .input(z.object({ code: z.string() }))
            .query(async ({ input }) => {
                return this.shareCodeService.getShareCodeInfo(input.code);
            }),
        hasActiveShareCode: this.trpc.procedure
            .input(z.object({ fileId: z.string() }))
            .query(async ({ input }) => {
                return this.shareCodeService.hasActiveShareCode(input.fileId);
            }),
        getFileShareHistory: this.trpc.procedure
            .input(z.object({ fileId: z.string() }))
            .query(async ({ input }) => {
                return this.shareCodeService.getFileShareHistory(input.fileId);
            }),
        getFileByShareCode: this.trpc.procedure
            .input(z.object({ code: z.string() }))
            .query(async ({ input }) => {
                return this.shareCodeService.getFileByShareCode(input.code);
            }),
        generateShareCodeByFileId: this.trpc.procedure
            .input(z.object({ fileId: z.string(), expiresAt: z.date(), canUseTimes: z.number() }))
            .mutation(async ({ input }) => {
                return this.shareCodeService.generateShareCodeByFileId(input.fileId, input.expiresAt, input.canUseTimes);
            }),
        getShareCodesWithResources: this.trpc.procedure
            .input(z.object({ page: z.number(), pageSize: z.number(), where: ShareCodeWhereInputSchema.optional() }))
            .query(async ({ input }) => {
                return this.shareCodeService.getShareCodesWithResources(input);
            }),
        softDeleteShareCodes: this.trpc.procedure
            .input(z.object({ ids: z.array(z.string()) }))
            .mutation(async ({ input }) => {
                return this.shareCodeService.softDeleteShareCodes(input.ids);
            }),
        updateShareCode: this.trpc.procedure
            .input(z.object({
                id: z.string(),
                data: z.object({
                    expiresAt: z.date().optional(),
                    canUseTimes: z.number().optional(),
                })
            }))
            .mutation(async ({ input }) => {
                return this.shareCodeService.updateShareCode(input.id, input.data);
            }),
    });
}