import { Controller, Post, Body, BadRequestException } from '@nestjs/common';
import { ChatbotService } from './chatbot.service';
import { MdxService } from '../mdx/mdx.service';
import { ChatRequestDto } from './dto/chat.dto';
import { ChatResponseDto } from './dto/chat.dto';

@Controller({ path: 'chatbot', version: '1' })
export class ChatbotController {
  constructor(
    private readonly chatbotService: ChatbotService,
    private readonly mdxService: MdxService,
  ) {}

  @Post('chat')
  async chat(@Body() chatRequestDto: ChatRequestDto): Promise<ChatResponseDto> {
    const { question, chatHistory = [] } = chatRequestDto;

    if (!question || question.trim() === '') {
      throw new BadRequestException('Question cannot be empty');
    }

    return await this.chatbotService.processQuestion(question, chatHistory);
  }

  // @Post('index')
  // async indexMdxFiles(@Body() body: { directoryPath: string }): Promise<{ message: string }> {
  //   await this.mdxService.processMdxFiles(body.directoryPath);
  //   return { message: 'MDX files indexed successfully' };
  // }
}
