import { Body, Controller, Get, Param, Patch, Post, Req, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';
import { TrackingService } from './tracking.service';
import { CalculateRouteDto, RecalculateEtaDto, UpdateDriverLocationDto } from './dto/tracking.dto';

@Controller('tracking')
@UseGuards(JwtAuthGuard)
export class TrackingController {
  constructor(private readonly trackingService: TrackingService) {}

  @Post('location')
  createLocation(@Req() req: { user: { sub: string; role: string } }, @Body() body: UpdateDriverLocationDto & { deliveryId: string }) {
    return this.trackingService.updateDriverLocation(req.user as never, body.deliveryId, body);
  }

  @Get('order/:orderId')
  getOrderTracking(@Req() req: { user: { sub: string; role: string } }, @Param('orderId') orderId: string) {
    return this.trackingService.getOrderTracking(orderId, req.user as never);
  }

  @Get('route/:orderId')
  getRoute(@Req() req: { user: { sub: string; role: string } }, @Param('orderId') orderId: string) {
    return this.trackingService.getRouteByOrder(orderId, req.user as never);
  }

  @Post('calculate-route')
  calculateRoute(@Body() body: CalculateRouteDto) {
    return this.trackingService.calculateRoute(body);
  }

  @Patch('recalculate-eta')
  recalculateEta(@Req() req: { user: { sub: string; role: string } }, @Body() body: RecalculateEtaDto) {
    return this.trackingService.recalculateEta(body.orderId, req.user as never);
  }
}
