import { FastifyRequest, FastifyReply } from 'fastify';
import { ChatGptService } from '../../middleware/chatgpt/ChatGptService';

export class ChatGptController {
    constructor(private chatGptService: ChatGptService) {}

    async handleChatGptRequest(request: FastifyRequest, reply: FastifyReply) {
        try {
            const response = await this.chatGptService.sendMessageToChatGpt(request.body as Record<string, unknown>, reply);
            if (!reply.sent) {
                reply.send(response);
            }
        } catch (error) {
            console.error('Error in ChatGptController:', error);
            if (!reply.sent) {
                reply.status(500).send({
                    responseText: '',
                    errorMessage: error instanceof Error ? error.message : 'Internal server error'
                });
            }
        }
    }
} 