import {
  Controller,
  Get,
  Query,
  UseGuards,
  NotFoundException,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { MerchantReviewService } from './review.service';
import { SellerJwtAuthGuard } from '@/common/guards/seller-jwt-auth.guard';
import { CurrentSeller } from '@/common/decorators/current-seller.decorator';
import { MerchantProfileService } from '../profile/profile.service';

@ApiTags('评价管理(商家)')
@Controller('merchant/reviews')
@UseGuards(SellerJwtAuthGuard)
@ApiBearerAuth()
export class MerchantReviewController {
  constructor(
    private readonly reviewService: MerchantReviewService,
    private readonly profileService: MerchantProfileService,
  ) {}

  @Get()
  @ApiOperation({ summary: '商家评价列表' })
  async getSellerReviews(
    @CurrentSeller('sub') sellerId: number,
    @Query('page') page: string = '1',
    @Query('limit') limit: string = '10',
    @Query('roomId') roomId?: string,
  ) {
    const merchant = await this.profileService.findBySellerId(sellerId);
    if (!merchant) throw new NotFoundException('店铺不存在');

    return this.reviewService.getSellerReviews(
      merchant.id,
      parseInt(page),
      parseInt(limit),
      roomId ? parseInt(roomId) : undefined,
    );
  }
}
