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

import { CreateTrainDto } from "./dto/create-train.dto";
import { TrainsService } from "./trains.service";

@ApiTags("trains")
// @UseGuards(JwtAuthGuard) — TODO: integrate @edr/auth
@Controller("trains")
export class TrainsController {
  constructor(private readonly trainsService: TrainsService) {}

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

  @Get()
  @ApiOperation({ summary: "List all trains" })
  findAll() {
    return this.trainsService.findAll();
  }

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