import { Controller, Get, Query } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiQuery } from '@nestjs/swagger';
import { TrendsService } from './trends.service';
import { TrendsQueryDto } from './dto/trends-query.dto';

@ApiTags('Trends')
@Controller('trends')
export class TrendsController {
  constructor(private readonly trendsService: TrendsService) {}

  @Get()
  @ApiOperation({ summary: 'Get trend data for specified metrics' })
  @ApiQuery({ name: 'metric', required: true, description: 'Metric type to query' })
  @ApiQuery({ name: 'startDate', required: true, description: 'Start date (ISO 8601)' })
  @ApiQuery({ name: 'endDate', required: true, description: 'End date (ISO 8601)' })
  @ApiQuery({ name: 'granularity', required: false, description: 'Time granularity (hour, day, week, month)' })
  async getTrends(@Query() query: TrendsQueryDto) {
    return this.trendsService.getTrends(query);
  }

  @Get('compare')
  @ApiOperation({ summary: 'Compare trends between two time periods' })
  async compareTrends(
    @Query() query: TrendsQueryDto,
    @Query('compareStartDate') compareStartDate: string,
    @Query('compareEndDate') compareEndDate: string,
  ) {
    return this.trendsService.compareTrends(query, compareStartDate, compareEndDate);
  }
}
