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 { CreateRentalDto } from "./dto/create-rental.dto";
import { RentalQueryDto } from "./dto/rental-query.dto";
import { UpdateRentalDto } from "./dto/update-rental.dto";
import { RentalsService } from "./rentals.service";

@UseGuards(JwtAuthGuard)
@Controller("rentals")
export class RentalsController {
  constructor(private readonly rentalsService: RentalsService) {}

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

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

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

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

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

  @Post(":id/rebuild-financials")
  rebuildFinancials(@Tenant() companyId: string, @Param("id") id: string) {
    return this.rentalsService.rebuildFinancials(companyId, id);
  }

  @Post("rebuild-all-financials")
  rebuildAllFinancials(@Tenant() companyId: string) {
    return this.rentalsService.rebuildAllFinancials(companyId);
  }

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