import {
  Controller,
  Get,
  Put,
  Body,
  Param,
  Query,
  UseGuards,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { AdminMerchantService } from './merchant.service';
import { JwtAuthGuard, RolesGuard } from '@/common';
import { Roles } from '@/common/decorators/roles.decorator';
import { QueryMerchantDto } from './dto/merchant.dto';

@ApiTags('商家管理(管理员)')
@Controller('admin/merchants')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin')
@ApiBearerAuth()
export class AdminMerchantController {
  constructor(private readonly adminMerchantService: AdminMerchantService) {}

  @Get()
  @ApiOperation({ summary: '获取商家列表' })
  async findAll(@Query() query: QueryMerchantDto) {
    return this.adminMerchantService.findAll(query);
  }

  @Put(':id/approve')
  @ApiOperation({ summary: '审核通过' })
  async approve(@Param('id') id: number) {
    return this.adminMerchantService.approve(id);
  }

  @Put(':id/reject')
  @ApiOperation({ summary: '审核拒绝' })
  async reject(@Param('id') id: number, @Body('reason') reason: string) {
    return this.adminMerchantService.reject(id, reason);
  }

  @Put(':id/freeze')
  @ApiOperation({ summary: '冻结店铺' })
  async freeze(@Param('id') id: number) {
    return this.adminMerchantService.freeze(id);
  }

  @Put(':id/unfreeze')
  @ApiOperation({ summary: '解冻店铺' })
  async unfreeze(@Param('id') id: number) {
    return this.adminMerchantService.unfreeze(id);
  }
}
