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

import { FleetManage, FleetView } from '../../common/booking-guards';
import { CreateLocomotiveDto } from './dto/create-locomotive.dto';
import { FilterLocomotivesDto } from './dto/filter-locomotives.dto';
import { UpdateLocomotiveDto } from './dto/update-locomotive.dto';
import { LocomotivesService } from './locomotives.service';

@ApiTags('locomotives')
@ApiBearerAuth()
@Controller('locomotives')
@FleetView()
export class LocomotivesController {
  constructor(private readonly locomotivesService: LocomotivesService) {}

  @Get()
  @ApiOperation({ summary: 'List locomotives' })
  findAll(@Query() filter: FilterLocomotivesDto) {
    return this.locomotivesService.findAll(filter);
  }

  @Get(':id')
  @ApiOperation({ summary: 'Get a locomotive by ID' })
  findOne(@Param('id', ParseUUIDPipe) id: string) {
    return this.locomotivesService.findById(id);
  }

  @Post()
  @FleetManage()
  @ApiOperation({ summary: 'Create a locomotive' })
  create(@Body() dto: CreateLocomotiveDto) {
    return this.locomotivesService.create(dto);
  }

  @Patch(':id')
  @FleetManage()
  @ApiOperation({ summary: 'Update a locomotive' })
  update(@Param('id', ParseUUIDPipe) id: string, @Body() dto: UpdateLocomotiveDto) {
    return this.locomotivesService.update(id, dto);
  }

  @Post(':id/decommission')
  @FleetManage()
  @ApiOperation({ summary: 'Decommission a locomotive' })
  decommission(@Param('id', ParseUUIDPipe) id: string) {
    return this.locomotivesService.decommission(id);
  }
}
