import {
  Controller,
  Get,
  Param,
  Query,
  UseGuards,
  Request,
} from '@nestjs/common';
import { OperationLogService } from './operation-log.service';
import { JwtAuthGuard } from './guards/jwt-auth.guard';
import { RolesGuard } from './guards/roles.guard';
import { Roles } from './decorators/roles.decorator';

@Controller('school')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('school')
export class SchoolOperationLogController {
  constructor(private readonly logService: OperationLogService) {}

  @Get('operation-logs')
  getLogs(@Request() req: any, @Query() query: any) {
    return this.logService.getLogs(req.user.tenantId, query);
  }

  @Get('operation-logs/stats')
  getStats(@Request() req: any, @Query() query: any) {
    return this.logService.getModuleStats(req.user.tenantId, query.startDate, query.endDate);
  }

  @Get('operation-logs/:id')
  getLogById(@Request() req: any, @Param('id') id: string) {
    return this.logService.getLogById(req.user.tenantId, +id);
  }
}

@Controller('admin')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin')
export class AdminOperationLogController {
  constructor(private readonly logService: OperationLogService) {}

  @Get('operation-logs')
  getLogs(@Query() query: any) {
    return this.logService.getLogs(null, query);
  }

  @Get('operation-logs/stats')
  getStats(@Query() query: any) {
    return this.logService.getModuleStats(null, query.startDate, query.endDate);
  }

  @Get('operation-logs/:id')
  getLogById(@Param('id') id: string) {
    return this.logService.getLogById(null, +id);
  }
}
