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

import { BookingStaff } from "../../common/booking-guards";
import { FREIGHT_PERMS } from "../../seed/freight-permissions.registry";
import { TrackingService } from "./tracking.service";

@ApiTags("tracking")
@ApiBearerAuth()
@Controller("tracking")
@BookingStaff(FREIGHT_PERMS.tracking.view)
export class TrackingController {
  constructor(private readonly trackingService: TrackingService) {}

  @Get(":consignmentId")
  @ApiOperation({ summary: "Get the tracking timeline for a consignment" })
  // TODO: scope to the caller's company — a staffer with tracking:view can
  // currently read any consignment's timeline. Add company-ownership filtering
  // once the ownership helper is wired into this module.
  findByConsignment(
    @Param("consignmentId", ParseUUIDPipe) consignmentId: string,
  ) {
    return this.trackingService.findByConsignment(consignmentId);
  }
}
