import { Body, Controller, Delete, Get, Param, Post, Put, Query } from '@nestjs/common';
import { SfgBomService } from './sfg-bom.service';

@Controller('sfg-bom')
export class SfgBomController {
  constructor(private readonly sfgBomService: SfgBomService) {}

  @Get('options')
  options() {
    return this.sfgBomService.options();
  }

  @Get('items')
  listItems(@Query() query: Record<string, string>) {
    return this.sfgBomService.listItems(query);
  }

  @Get('items/export')
  exportItems(@Query('format') format = 'xlsx') {
    return this.sfgBomService.exportItems(format);
  }

  @Get('items/:id')
  getItem(@Param('id') id: string) {
    return this.sfgBomService.getItem(id);
  }

  @Post('items')
  createItem(@Body() body: any) {
    return this.sfgBomService.createItem(body);
  }

  @Put('items/:id')
  updateItem(@Param('id') id: string, @Body() body: any) {
    return this.sfgBomService.updateItem(id, body);
  }

  @Delete('items/:id')
  deleteItem(@Param('id') id: string) {
    return this.sfgBomService.deleteItem(id);
  }

  @Get('boms')
  listBoms(@Query() query: Record<string, string>) {
    return this.sfgBomService.listBoms(query);
  }

  @Get('boms/export')
  exportBoms(@Query('format') format = 'xlsx', @Query('bomType') bomType = '') {
    return this.sfgBomService.exportBoms(format, bomType);
  }

  @Get('boms/:id')
  getBom(@Param('id') id: string): Promise<any> {
    return this.sfgBomService.getBom(id);
  }

  @Get('processes')
  listProcesses(@Query() query: Record<string, string>) {
    return this.sfgBomService.listProcesses(query);
  }

  @Get('processes/export')
  exportProcesses(@Query('format') format = 'xlsx') {
    return this.sfgBomService.exportProcesses(format);
  }

  @Get('final-product-options')
  finalProductOptions(@Query() query: Record<string, string>) {
    return this.sfgBomService.finalProductOptions(query);
  }

  @Get('final-cost')
  finalCost(@Query() query: Record<string, string>): Promise<any> {
    return this.sfgBomService.finalCost(query);
  }

  @Post('import/preview')
  previewWorkbook(@Body() body: any) {
    return this.sfgBomService.previewWorkbook(body);
  }

  @Post('import/commit')
  importWorkbook(@Body() body: any) {
    return this.sfgBomService.importWorkbook(body);
  }
}
