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 { CreateReservationDto } from "./dto/create-reservation.dto";
import { ReservationQueryDto } from "./dto/reservation-query.dto";
import { UpdateReservationDto } from "./dto/update-reservation.dto";
import { ReservationsService } from "./reservations.service";

@UseGuards(JwtAuthGuard)
@Controller("reservations")
export class ReservationsController {
  constructor(private readonly reservationsService: ReservationsService) {}

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

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

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

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

  @Post(":id/convert")
  convertToRental(@Tenant() companyId: string, @Param("id") id: string) {
    return this.reservationsService.convertToRental(companyId, id);
  }

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

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