import {
  Body,
  Controller,
  Get,
  Param,
  ParseUUIDPipe,
  Post,
  Query,
} from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';

import { CreateContainerTrainScheduleDto } from './dto/create-container-train-schedule.dto';
import { GetEligibleContainerBookingsDto } from './dto/get-eligible-container-bookings.dto';
import { PreviewContainerTrainScheduleDto } from './dto/preview-container-train-schedule.dto';
import { TrainSchedulingService } from './train-scheduling.service';

@ApiTags('train-scheduling')
@ApiBearerAuth()
@Controller('train-scheduling')
export class TrainSchedulingController {
  constructor(private readonly trainSchedulingService: TrainSchedulingService) {}

  @Get('container/eligible-bookings')
  @ApiOperation({ summary: 'List eligible container bookings' })
  getEligibleContainerBookings(@Query() query: GetEligibleContainerBookingsDto) {
    return this.trainSchedulingService.getEligibleContainerBookings(query);
  }

  @Post('container/preview')
  @ApiOperation({ summary: 'Preview a container train schedule' })
  previewContainerTrainSchedule(@Body() dto: PreviewContainerTrainScheduleDto) {
    return this.trainSchedulingService.previewContainerTrainSchedule(dto);
  }

  @Post('container/schedules')
  @ApiOperation({ summary: 'Create a container train schedule' })
  createContainerTrainSchedule(@Body() dto: CreateContainerTrainScheduleDto) {
    return this.trainSchedulingService.createContainerTrainSchedule(dto);
  }

  @Get('container/schedules')
  @ApiOperation({ summary: 'List container train schedules' })
  getContainerTrainSchedules() {
    return this.trainSchedulingService.getContainerTrainSchedules();
  }

  @Get('container/schedules/:id')
  @ApiOperation({ summary: 'Get container train schedule detail' })
  getContainerTrainScheduleById(@Param('id', ParseUUIDPipe) id: string) {
    return this.trainSchedulingService.getContainerTrainScheduleById(id);
  }

  @Post('container/schedules/:id/cancel')
  @ApiOperation({ summary: 'Cancel container train schedule' })
  cancelTrainSchedule(@Param('id', ParseUUIDPipe) id: string) {
    return this.trainSchedulingService.cancelTrainSchedule(id);
  }
}
