import { Controller, Get, Query, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { JwtAuthGuard } from '@/common/guards/jwt-auth.guard';
import { RolesGuard } from '@/common/guards/roles.guard';
import { Roles } from '@/common/decorators/roles.decorator';
import { CurrentUser } from '@/common/decorators/current-user.decorator';
import { StatisticsService } from './statistics.service';

@ApiTags('商家统计')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('merchant')
@Controller('merchant/statistics')
export class StatisticsSellerController {
  constructor(private readonly statisticsService: StatisticsService) {}

  @Get('overview')
  @ApiOperation({ summary: '获取数据概览' })
  async getOverview(@CurrentUser() user: any) {
    return this.statisticsService.getOverview(user.merchantId);
  }

  @Get('income-trend')
  @ApiOperation({ summary: '获取收入趋势' })
  async getIncomeTrend(
    @CurrentUser() user: any,
    @Query('type') type: 'day' | 'week' | 'month' = 'day',
  ) {
    return this.statisticsService.getIncomeTrend(user.merchantId, type);
  }
}
