import {
  Controller, Get, Post, Put, Patch, Param, Body, Query, UseGuards,
} from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { OrdersService } from './orders.service';
import { CreateOrderDto } from './dto/create-order.dto';
import { UpdateOrderDto } from './dto/update-order.dto';
import { CompleteOrderDto } from './dto/complete-order.dto';
import { QueryOrderDto } from './dto/query-order.dto';
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
import { CurrentTenant, CurrentUser } from '../../common/decorators/tenant.decorator';

@ApiTags('Service Orders')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Controller('orders')
export class OrdersController {
  constructor(private service: OrdersService) {}

  @Post()
  create(@CurrentTenant() tenantId: string, @CurrentUser() user: any, @Body() dto: CreateOrderDto) {
    return this.service.create(tenantId, user.id, dto);
  }

  @Get()
  findAll(@CurrentTenant() tenantId: string, @Query() query: QueryOrderDto) {
    return this.service.findAll(tenantId, query);
  }

  @Get(':id')
  findOne(@CurrentTenant() tenantId: string, @Param('id') id: string) {
    return this.service.findOne(tenantId, id);
  }

  @Put(':id')
  update(@CurrentTenant() tenantId: string, @Param('id') id: string, @Body() dto: UpdateOrderDto) {
    return this.service.update(tenantId, id, dto);
  }

  @Patch(':id/complete')
  complete(@CurrentTenant() tenantId: string, @Param('id') id: string, @Body() dto: CompleteOrderDto) {
    return this.service.complete(tenantId, id, dto);
  }
}
