import { Body, Controller, Get, Post, Req, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { ActiveCompanyGuard } from '../common/guards/active-company.guard';
import { PurchaseDto } from './dto/purchase.dto';
import { InventoryService } from './inventory.service';

@ApiTags('inventory')
@Controller('inventory')
export class InventoryController {
  constructor(private readonly inventoryService: InventoryService) {}

  @Get()
  async list() {
    return this.inventoryService.listProducts();
  }

  @Post('purchase')
  @UseGuards(JwtAuthGuard, ActiveCompanyGuard)
  @ApiBearerAuth()
  async purchase(@Body() dto: PurchaseDto, @Req() req: any) {
    return this.inventoryService.purchaseProduct(req.user.sub, dto);
  }
}
