import {
  Controller,
  Get,
  Post,
  Patch,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
} from '@nestjs/common';
import { FlightsService } from './flights.service';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { RolesGuard } from '../auth/guards/roles.guard';
import { Roles } from '../auth/decorators/roles.decorator';
import { Role } from '@prisma/client';
import { CreateFlightDto, UpdateFlightDto } from './dto';

@Controller('flights')
@UseGuards(JwtAuthGuard, RolesGuard)
export class FlightsController {
  constructor(private readonly flightsService: FlightsService) {}

  @Post()
  @Roles(Role.ADMINISTRATOR, Role.COORDINATOR)
  create(@Body() createFlightDto: CreateFlightDto) {
    return this.flightsService.create(createFlightDto);
  }

  @Get()
  @Roles(Role.ADMINISTRATOR, Role.COORDINATOR)
  findAll() {
    return this.flightsService.findAll();
  }

  @Get('status/:flightNumber')
  @Roles(Role.ADMINISTRATOR, Role.COORDINATOR)
  getFlightStatus(
    @Param('flightNumber') flightNumber: string,
    @Query('date') date?: string,
  ) {
    return this.flightsService.getFlightStatus(flightNumber, date);
  }

  @Get('vip/:vipId')
  @Roles(Role.ADMINISTRATOR, Role.COORDINATOR)
  findByVip(@Param('vipId') vipId: string) {
    return this.flightsService.findByVip(vipId);
  }

  @Get(':id')
  @Roles(Role.ADMINISTRATOR, Role.COORDINATOR)
  findOne(@Param('id') id: string) {
    return this.flightsService.findOne(id);
  }

  @Patch(':id')
  @Roles(Role.ADMINISTRATOR, Role.COORDINATOR)
  update(@Param('id') id: string, @Body() updateFlightDto: UpdateFlightDto) {
    return this.flightsService.update(id, updateFlightDto);
  }

  @Delete(':id')
  @Roles(Role.ADMINISTRATOR, Role.COORDINATOR)
  remove(
    @Param('id') id: string,
    @Query('hard') hard?: string,
  ) {
    const isHardDelete = hard === 'true';
    return this.flightsService.remove(id, isHardDelete);
  }
}
