import { Body, Controller, Get, Post, Render, Req, UploadedFile, UseInterceptors, Param } from '@nestjs/common'
import { Public } from '../auth/public.decorator'
import { FileInterceptor } from '@nestjs/platform-express'
import { ChatPdfService } from './chat-pdf.service'

@Controller('chat-pdf')
export class ChatPdfController {
    constructor(private readonly chatPdfService: ChatPdfService) {}

    @Public()
    @Post('upload/:code')
    @UseInterceptors(FileInterceptor('file'))
    public async uploadFile(@UploadedFile() file: Express.Multer.File, @Param('code') code: string) {
        return await this.chatPdfService.upload(file, code)
    }

    @Public()
    @Post('upload')
    @UseInterceptors(FileInterceptor('file'))
    public async firstUpload(@UploadedFile() file: Express.Multer.File) {
        return await this.chatPdfService.firstUpload(file)
    }

    // @Public()
    // @Post('apiUpload')
    // @UseInterceptors(FileInterceptor('file'))
    // public async apiUpload(@UploadedFile() file: Express.Multer.File, userId: number) {
    //     return await this.chatPdfService.upload(file)
    // }

    @Public()
    @Post('ask')
    public async ask(@Body() { q, name }) {
        return await this.chatPdfService.ask(q, name)
    }

    @Public()
    @Post('customerServiceAsk')
    public async customerAsk(@Body() { q, name }) {
        return await this.chatPdfService.customerAsk(q, name)
    }

    @Public()
    @Public()
    @Get('ui')
    @Render('chatPdf')
    public async answer() {
        return {}
    }

    @Public()
    @Public()
    @Get('customerUi')
    @Render('customerChatPdf')
    public async customerAnswer() {
        return {}
    }
}
