import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  ParseIntPipe,
  Patch,
  Post,
  Query,
} from '@nestjs/common';
import { CreateInventoryDto } from './dto/create-inventory.dto';
import { UpdateInventoryDto } from './dto/update-inventory.dto';
import { InventoryService } from './inventory.service';
import { ConsumeInventoryDto } from './dto/consume-inventory.dto';

@Controller('inventory')
export class InventoryController {
  constructor(private readonly inventoryService: InventoryService) {}
 
 @Post(':id/consume')
 consume(
   @Param('id', ParseIntPipe) id: number,
   @Body() body: ConsumeInventoryDto,
  ) {
  return this.inventoryService.consume(id, body);
  }
  
  @Get(':id/consumption-history')
findConsumptionHistory(@Param('id', ParseIntPipe) id: number) {
  return this.inventoryService.findConsumptionHistory(id);
  } 
 
  @Get()
  findAll(
    @Query('location') location?: string,
    @Query('sort') sort?: string,
  ) {
    return this.inventoryService.findAll({ location, sort });
  }

  @Get('expiring')
  findExpiring() {
    return this.inventoryService.findExpiring();
  }

  @Post()
  create(@Body() body: CreateInventoryDto) {
    return this.inventoryService.create(body);
  }

  @Patch(':id')
  update(
    @Param('id', ParseIntPipe) id: number,
    @Body() body: UpdateInventoryDto,
  ) {
    return this.inventoryService.update(id, body);
  }

  @Delete(':id')
  remove(@Param('id', ParseIntPipe) id: number) {
    return this.inventoryService.remove(id);
  }
}