import { Controller, Body, Patch, Param, Post, UseGuards } from '@nestjs/common';
import { InventoryService } from './inventory.service';
import { SetStockDto } from './dto/set-stock.dto';
import { BulkSetStockDto } from './dto/bulk-set-stock.dto';
import { ApiTags, ApiOperation, ApiBody, ApiParam, ApiBearerAuth } from '@nestjs/swagger';
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
import { RestId } from 'src/common/decorators';
import { Inventory } from './entities/inventory.entity';
import { Permissions } from 'src/common/decorators/permissions.decorator';
import { Permission } from 'src/common/enums/permission.enum';

@ApiTags('inventory')
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Permissions(Permission.MANAGE_FOODS)
@Controller()
export class InventoryController {
  constructor(private readonly inventoryService: InventoryService) { }

  @Patch('admin/inventory/food/:foodId/stock')
  @ApiOperation({ summary: 'Set available and total stock for a food item' })
  @ApiParam({ name: 'foodId', description: 'Food ID' })
  @ApiBody({ type: SetStockDto })
  setStockForFood(
    @Param('foodId') foodId: string,
    @RestId() restaurantId: string,
    @Body() setStockDto: SetStockDto,
  ): Promise<Inventory> {
    return this.inventoryService.setStockForFood(foodId, restaurantId, setStockDto);
  }

  @Post('admin/inventory/foods/stock/bulk')
  @ApiOperation({ summary: 'Bulk set available and total stock for multiple food items' })
  @ApiBody({ type: BulkSetStockDto })
  bulkSetStockForFoods(@RestId() restaurantId: string, @Body() bulkSetStockDto: BulkSetStockDto): Promise<Inventory[]> {
    return this.inventoryService.bulkSetStockForFoods(restaurantId, bulkSetStockDto);
  }
}
