/**
 * Glinfo Controller - INF lookup API (full CRUD for GeneralSetup)
 */
import { Controller, Get, Post, Patch, Delete, Query, Param, Body, UseGuards } from '@nestjs/common';
import { GlinfoService } from './glinfo.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';

@Controller('glinfo')
@UseGuards(JwtAuthGuard)
export class GlinfoController {
  constructor(private glinfoService: GlinfoService) {}

  @Get()
  findByType(@Query('infType') infType: string) {
    const type = parseInt(infType || '1', 10);
    return this.glinfoService.findByType(type);
  }

  @Post()
  create(@Body() body: { infType: number; infId: number; infName?: string }) {
    return this.glinfoService.create(body.infType, body.infId, body.infName);
  }

  @Patch(':infType/:infId')
  update(
    @Param('infType') infType: string,
    @Param('infId') infId: string,
    @Body() body: { infName?: string },
  ) {
    return this.glinfoService.update(parseInt(infType, 10), parseInt(infId, 10), body.infName);
  }

  @Delete(':infType/:infId')
  delete(@Param('infType') infType: string, @Param('infId') infId: string) {
    return this.glinfoService.delete(parseInt(infType, 10), parseInt(infId, 10));
  }
}
