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

import { FleetManage, FleetView } from "../../common/booking-guards";
import { CreateTrainDto } from "./dto/create-train.dto";
import { UpdateTrainDto } from "./dto/update-train.dto";
import { TrainsService } from "./trains.service";

@ApiTags("trains")
@Controller("trains")
@FleetView()
export class TrainsController {
  constructor(private readonly trainsService: TrainsService) {}

  @Post()
  @FleetManage()
  @ApiOperation({ summary: "Register a new train" })
  create(@Body() dto: CreateTrainDto) {
    return this.trainsService.create(dto);
  }

  @Get()
  @ApiOperation({ summary: "List all trains" })
  findAll(@Query() query: Record<string, string | undefined>) {
    return this.trainsService.findAll(query);
  }

  @Get(":id")
  @ApiOperation({ summary: "Get a train by ID" })
  findOne(@Param("id", ParseUUIDPipe) id: string) {
    return this.trainsService.findById(id);
  }

  @Patch(":id")
  @FleetManage()
  @ApiOperation({ summary: "Update a train" })
  update(@Param("id", ParseUUIDPipe) id: string, @Body() dto: UpdateTrainDto) {
    return this.trainsService.update(id, dto);
  }

  @Delete(":id")
  @FleetManage()
  @ApiOperation({ summary: "Delete a train" })
  remove(@Param("id", ParseUUIDPipe) id: string) {
    return this.trainsService.remove(id);
  }
}
