/**
 * Items Controller
 *
 * REST endpoints for inventory items
 * Replaces: ItemsProvider, GetItem in original server
 */
import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common';
import { ItemsService } from './items.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';

@Controller('items')
@UseGuards(JwtAuthGuard)
export class ItemsController {
  constructor(private itemsService: ItemsService) {}

  /**
   * GET /api/items
   * Get all items, optional filter by mgNo, mtNo
   */
  @Get()
  findAll(
    @Query('mgNo') mgNo?: string,
    @Query('mtNo') mtNo?: string,
    @Query('mtUp') mtUp?: string,
  ) {
    return this.itemsService.findAll(mgNo, mtNo, mtUp);
  }

  /**
   * GET /api/items/:mgNo/:mtNo
   * Get single item by mg_no and mt_no
   * Query: mtrCode (default 1)
   */
  @Get(':mgNo/:mtNo')
  getItem(
    @Param('mgNo') mgNo: string,
    @Param('mtNo') mtNo: string,
    @Query('mtrCode') mtrCode?: string,
  ) {
    const code = mtrCode ? parseInt(mtrCode, 10) : 1;
    return this.itemsService.getItem(mgNo, mtNo, code);
  }
}
