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

import { FleetManage, FleetView } from "../../common/booking-guards";
import { ConsignmentsService } from "./consignments.service";
import { CreateConsignmentDto } from "./dto/create-consignment.dto";
import { FilterConsignmentDto } from "./dto/filter-consignment.dto";

@ApiTags("consignments")
@Controller("consignments")
@FleetView()
export class ConsignmentsController {
  constructor(private readonly consignmentsService: ConsignmentsService) {}

  @Post()
  @FleetManage()
  @ApiOperation({ summary: "Create a new consignment" })
  create(@Body() dto: CreateConsignmentDto) {
    return this.consignmentsService.create(dto);
  }

  @Get()
  @ApiOperation({ summary: "List consignments (paginated)" })
  findAll(@Query() filter: FilterConsignmentDto) {
    return this.consignmentsService.findAll(filter);
  }

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