import {
  Controller,
  Post,
  Delete,
  Param,
  Body,
  UseGuards,
  HttpCode,
  HttpStatus,
} from '@nestjs/common';
import {
  ApiTags,
  ApiOperation,
  ApiBearerAuth,
  ApiResponse,
  ApiParam,
} from '@nestjs/swagger';
import { ProvisioningService, Club } from './provisioning.service';
import { CreateClubDto } from './dto/create-club.dto';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { RolesGuard } from '../auth/guards/roles.guard';
import { Roles, UserRole } from '../../common/decorators/roles.decorator';

@ApiTags('Provisioning')
@ApiBearerAuth()
@Controller('clubs')
@UseGuards(JwtAuthGuard, RolesGuard)
export class ProvisioningController {
  constructor(private readonly provisioningService: ProvisioningService) {}

  @Post()
  @Roles(UserRole.SUPER_ADMIN)
  @ApiOperation({ summary: 'Provision a new club environment' })
  @ApiResponse({ status: 201, description: 'Club created successfully' })
  @ApiResponse({ status: 403, description: 'Super admin access required' })
  @ApiResponse({ status: 409, description: 'Club with this slug already exists' })
  async provisionClub(@Body() dto: CreateClubDto): Promise<Club> {
    return this.provisioningService.provisionClub(dto);
  }

  @Delete(':id')
  @Roles(UserRole.SUPER_ADMIN)
  @HttpCode(HttpStatus.NO_CONTENT)
  @ApiOperation({ summary: 'Deprovision (deactivate) a club' })
  @ApiParam({ name: 'id', description: 'Club UUID' })
  @ApiResponse({ status: 204, description: 'Club deactivated' })
  @ApiResponse({ status: 403, description: 'Super admin access required' })
  async deprovisionClub(@Param('id') id: string): Promise<void> {
    await this.provisioningService.deprovisionClub(id);
  }
}
