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 { CreateSupplierDto } from "./dto/create-supplier.dto";
import { SupplierQueryDto } from "./dto/supplier-query.dto";
import { UpdateSupplierDto } from "./dto/update-supplier.dto";
import { SuppliersService } from "./suppliers.service";

@UseGuards(JwtAuthGuard)
@Controller("suppliers")
export class SuppliersController {
  constructor(private readonly suppliersService: SuppliersService) {}

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

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

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

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

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

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