import { Controller, Get, Post, Patch, Delete, Param, Body, Req, UseGuards } from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
import { AdminConversationService } from './admin-conversation.service';
import { CreateConversationDto, UpdateConversationDto } from './dto';
import { AdminAuthGuard } from '../../common/guards/admin-auth.guard';

@ApiTags('admin-conversation')
@Controller('admin-api/conversations')
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
export class AdminConversationController {
  constructor(private readonly svc: AdminConversationService) {}

  @Get()
  async list(@Req() req: any) {
    return this.svc.list(req.adminUser.id);
  }

  @Get(':id/messages')
  @ApiOperation({ summary: '获取对话的历史消息' })
  async messages(@Req() req: any, @Param('id') id: string) {
    return this.svc.getMessages(id, req.adminUser.id);
  }

  @Post()
  async create(@Req() req: any, @Body() dto: CreateConversationDto) {
    return this.svc.create(req.adminUser.id, dto.title);
  }

  @Patch(':id')
  async update(@Req() req: any, @Param('id') id: string, @Body() dto: UpdateConversationDto) {
    await this.svc.updateTitle(id, req.adminUser.id, dto.title);
    return { success: true };
  }

  @Delete(':id')
  async delete(@Req() req: any, @Param('id') id: string) {
    await this.svc.delete(id, req.adminUser.id);
    return { success: true };
  }
}
