import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseGuards, Req } from '@nestjs/common';
import { ClientsService } from './clients.service';
import { CreateClientDto } from './dto/create-client.dto';
import { UpdateClientDto } from './dto/update-client.dto';
import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard';

@UseGuards(JwtAuthGuard)
@Controller('clients')
export class ClientsController {
  constructor(private readonly clientsService: ClientsService) { }

  @Post()
  create(@Body() createCylinderDto: CreateClientDto, @Req() req: any) {
    return this.clientsService.create(createCylinderDto, req.user);
  }

  @Patch(":id")
  updateCylinder(
    @Param("id") id: string,
    @Body() updateCylinderDto: UpdateClientDto,
    @Req() req?: any,
  ) {
    return this.clientsService.update(id, updateCylinderDto, req.user);
  }

  @Get()
  findAll(
    @Query("limit") limit?: string,
    @Query("page") page?: string,
    @Query("q") query?: string,
    @Query("warehouseId") warehouseId?: string,
    @Req() req?: any,
  ) {
    const pageNumber = parseInt(page ?? "1");
    const perPage = parseInt(limit ?? "10");
    return this.clientsService.findAll(pageNumber, perPage, query, warehouseId, req.user);
  }

  @Get("all")
  getAllClients(
    @Query("page") page?: string,
    @Query("perPage") perPage?: string,
    @Query("search") search?: string,
    @Query("warehouseId") warehouseId?: string,
  ) {
    const pageNumber = parseInt(page ?? "1");
    const itemsPerPage = parseInt(perPage ?? "10");
    return this.clientsService.getAllClients(pageNumber, itemsPerPage, search, warehouseId);
  }

  @Get("search")
  searchCylinder(
    @Query("q") query: string,
    @Query("limit") limit?: string,
    @Query("page") page?: string
  ) {
    const pageNumber = parseInt(page ?? "1");
    const perPage = parseInt(limit ?? "10");
    return this.clientsService.searchClient(query, pageNumber, perPage);
  }


  @Get(":id")
  findOne(@Param("id") id: string) {
    return this.clientsService.findOne(id);
  }

  // Delete a cylinder by ID
  @Delete(":id")
  removeCylinder(@Param("id") id: string) {
    return this.clientsService.remove(id);
  }


}
