import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Param,
  Body,
  UseGuards,
  Query,
} from '@nestjs/common';
import { TenantService } from './tenant.service';
import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';
import { RolesGuard } from '../common/guards/roles.guard';
import { Roles } from '../common/decorators/roles.decorator';
import {
  TenantQueryDto,
  CreateTenantDto,
  UpdateTenantDto,
  UpdateTenantQuotaDto,
  UpdateTenantStatusDto,
} from './dto/tenant.dto';

@Controller('admin/tenants')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin')
export class TenantController {
  constructor(private readonly tenantService: TenantService) {}

  @Get()
  findAll(@Query() query: TenantQueryDto) {
    return this.tenantService.findAllPaginated(query);
  }

  @Get('stats')
  getStats() {
    return this.tenantService.getStats();
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.tenantService.findOne(+id);
  }

  @Post()
  create(@Body() createTenantDto: CreateTenantDto) {
    return this.tenantService.create(createTenantDto);
  }

  @Put(':id')
  update(@Param('id') id: string, @Body() updateTenantDto: UpdateTenantDto) {
    return this.tenantService.update(+id, updateTenantDto);
  }

  @Put(':id/quota')
  updateQuota(@Param('id') id: string, @Body() dto: UpdateTenantQuotaDto) {
    return this.tenantService.updateQuota(+id, dto);
  }

  @Put(':id/status')
  updateStatus(@Param('id') id: string, @Body() dto: UpdateTenantStatusDto) {
    return this.tenantService.updateStatus(+id, dto);
  }

  @Post(':id/reset-password')
  resetPassword(@Param('id') id: string) {
    return this.tenantService.resetPassword(+id);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.tenantService.remove(+id);
  }
}
