import { Controller, Get, Query, Req, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { TodaySummaryQueryDto } from './dto/today-summary-query.dto';
import { TodayService } from './today.service';

@ApiTags('today')
@ApiBearerAuth('JWT-auth')
@UseGuards(JwtAuthGuard)
@Controller('today')
export class TodayController {
  constructor(private readonly todayService: TodayService) {}

  @Get('summary')
  @ApiOperation({
    summary:
      'Permission-aware dashboard summary for the Today tab (TAB_TODAY_READ or owner)',
  })
  getSummary(
    @Query() query: TodaySummaryQueryDto,
    @Req() req: { user: { id: string; organizationId?: string; language?: string } },
  ) {
    const organizationId = this.todayService.getOrganizationIdFromUser(req.user);
    return this.todayService.getSummary(
      req.user.id,
      organizationId,
      query,
      req.user.language,
    );
  }
}
