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 { CreateCargoDto } from './dto/create-cargo.dto';
import { UpdateCargoDto } from './dto/update-cargo.dto';
import { LoadCargoDto } from './dto/load-cargo.dto';
import { DeliverCargoDto } from './dto/deliver-cargo.dto';
import { CargoesService } from './cargoes.service';

@ApiTags('cargoes')
@Controller('cargoes')
@FleetView()
export class CargoesController {
  constructor(private readonly cargoesService: CargoesService) {}

  @Post()
  @FleetManage()
  @ApiOperation({ summary: 'Create a new cargo' })
  create(@Body() dto: CreateCargoDto) {
    return this.cargoesService.create(dto);
  }

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

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

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

  @Delete(':id')
  @FleetManage()
  @ApiOperation({ summary: 'Delete a cargo' })
  remove(@Param('id', ParseUUIDPipe) id: string) {
    return this.cargoesService.remove(id);
  }

  @Post(':id/load')
  @FleetManage()
  @ApiOperation({ summary: 'Load cargo into a container' })
  load(@Param('id', ParseUUIDPipe) id: string, @Body() dto: LoadCargoDto) {
    return this.cargoesService.loadCargo(id, dto);
  }

  @Post(':id/unload')
  @FleetManage()
  @ApiOperation({ summary: 'Unload cargo from container' })
  unload(@Param('id', ParseUUIDPipe) id: string) {
    return this.cargoesService.unloadCargo(id);
  }

  @Post(':id/deliver')
  @FleetManage()
  @ApiOperation({ summary: 'Mark cargo as delivered' })
  deliver(@Param('id', ParseUUIDPipe) id: string, @Body() dto?: DeliverCargoDto) {
    return this.cargoesService.deliverCargo(id, dto);
  }
}
