import { Controller, Get, Post, Put, Delete, Body, Param, Query, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam } from '@nestjs/swagger';
import { AdminManageService } from './admin-manage.service';
import { CreateAdminDto, UpdateAdminDto, UpdateAdminPasswordDto, QueryAdminDto } from './dto/admin.dto';
import { JwtAuthGuard, RolesGuard, Roles, AdminRole } from '@/common';

@ApiTags('管理端-管理员管理')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(AdminRole.SUPER_ADMIN)
@Controller('admin/admins')
export class AdminManageController {
  constructor(private readonly adminManageService: AdminManageService) {}

  @Get()
  @ApiOperation({ summary: '获取管理员列表' })
  async getAdminList(@Query() query: QueryAdminDto) {
    return this.adminManageService.getAdminList(query);
  }

  @Get(':id')
  @ApiOperation({ summary: '获取管理员详情' })
  @ApiParam({ name: 'id', description: '管理员ID' })
  async getAdminById(@Param('id') id: number) {
    return this.adminManageService.getAdminById(id);
  }

  @Post()
  @ApiOperation({ summary: '创建管理员' })
  async createAdmin(@Body() dto: CreateAdminDto) {
    return this.adminManageService.createAdmin(dto);
  }

  @Put(':id')
  @ApiOperation({ summary: '更新管理员信息' })
  @ApiParam({ name: 'id', description: '管理员ID' })
  async updateAdmin(@Param('id') id: number, @Body() dto: UpdateAdminDto) {
    return this.adminManageService.updateAdmin(id, dto);
  }

  @Put(':id/password')
  @ApiOperation({ summary: '重置管理员密码' })
  @ApiParam({ name: 'id', description: '管理员ID' })
  async updateAdminPassword(@Param('id') id: number, @Body() dto: UpdateAdminPasswordDto) {
    return this.adminManageService.updateAdminPassword(id, dto);
  }

  @Put(':id/toggle-status')
  @ApiOperation({ summary: '切换管理员状态' })
  @ApiParam({ name: 'id', description: '管理员ID' })
  async toggleAdminStatus(@Param('id') id: number) {
    return this.adminManageService.toggleAdminStatus(id);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除管理员' })
  @ApiParam({ name: 'id', description: '管理员ID' })
  async deleteAdmin(@Param('id') id: number) {
    return this.adminManageService.deleteAdmin(id);
  }
}
