import {
  Controller,
  Get,
  UseGuards,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { AdminCouponAnalyticsService } from '../../../application/services/admin-coupon-analytics.service';
import { RolesGuard, Roles } from '../guards/roles.guard';

@ApiTags('Admin - Coupon Analytics')
@Controller('admin/analytics/coupons')
@UseGuards(AuthGuard('jwt'), RolesGuard)
@Roles('admin')
@ApiBearerAuth()
export class AdminAnalyticsController {
  constructor(private readonly analyticsService: AdminCouponAnalyticsService) {}

  @Get('stats')
  @ApiOperation({ summary: 'Coupon stats: total supply, circulation, velocity' })
  async getCouponStats() {
    const result = await this.analyticsService.getCouponStats();
    return { code: 0, data: result };
  }

  @Get('by-issuer')
  @ApiOperation({ summary: 'Coupon distribution by issuer' })
  async getCouponsByIssuer() {
    const result = await this.analyticsService.getCouponsByIssuer();
    return { code: 0, data: result };
  }

  @Get('by-category')
  @ApiOperation({ summary: 'Coupon distribution by category' })
  async getCouponsByCategory() {
    const result = await this.analyticsService.getCouponsByCategory();
    return { code: 0, data: result };
  }

  @Get('lifecycle')
  @ApiOperation({ summary: 'Coupon lifecycle pipeline: issued/sold/redeemed counts' })
  async getLifecycle() {
    const result = await this.analyticsService.getLifecycle();
    return { code: 0, data: result };
  }

  @Get('redemption-rate')
  @ApiOperation({ summary: 'Monthly redemption rate trends' })
  async getRedemptionRate() {
    const result = await this.analyticsService.getRedemptionRate();
    return { code: 0, data: result };
  }

  @Get('discount-distribution')
  @ApiOperation({ summary: 'Secondary market discount distribution (price vs face value)' })
  async getDiscountDistribution() {
    const result = await this.analyticsService.getDiscountDistribution();
    return { code: 0, data: result };
  }
}
