import { Body, Controller, Delete, Get, Param, Patch, Post, Query, UseGuards } from "@nestjs/common";
import { Tenant } from "../../common/decorators/tenant.decorator";
import { JwtAuthGuard } from "../../common/guards/jwt-auth.guard";
import { CreateServiceOrderDto } from "./dto/create-service-order.dto";
import { ServiceOrderQueryDto } from "./dto/service-order-query.dto";
import { UpdateServiceOrderDto } from "./dto/update-service-order.dto";
import { MaintenanceService } from "./maintenance.service";

@UseGuards(JwtAuthGuard)
@Controller("maintenance")
export class MaintenanceController {
  constructor(private readonly maintenanceService: MaintenanceService) {}

  @Get()
  findAll(@Tenant() companyId: string, @Query() query: ServiceOrderQueryDto) {
    return this.maintenanceService.findAll(companyId, query);
  }

  @Get("stats")
  getStats(@Tenant() companyId: string) {
    return this.maintenanceService.getStats(companyId);
  }

  @Get(":id")
  findOne(@Tenant() companyId: string, @Param("id") id: string) {
    return this.maintenanceService.findOne(companyId, id);
  }

  @Post()
  create(@Tenant() companyId: string, @Body() dto: CreateServiceOrderDto) {
    return this.maintenanceService.create(companyId, dto);
  }

  @Patch(":id")
  update(@Tenant() companyId: string, @Param("id") id: string, @Body() dto: UpdateServiceOrderDto) {
    return this.maintenanceService.update(companyId, id, dto);
  }

  @Delete(":id")
  remove(@Tenant() companyId: string, @Param("id") id: string) {
    return this.maintenanceService.remove(companyId, id);
  }
}
