import { Body, Controller, Delete, Get, Param, Post, Put, Query } from '@nestjs/common';
import { MachineryService } from './machinery.service';

@Controller('machinery')
export class MachineryController {
  constructor(private readonly machineryService: MachineryService) {}

  @Get()
  list(@Query() query: Record<string, string>) {
    return this.machineryService.list(query);
  }

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

  @Get('export/:module')
  export(@Param('module') moduleName: string, @Query() query: Record<string, string>) {
    return this.machineryService.export(moduleName, query);
  }

  @Get('sample/:module')
  sample(@Param('module') moduleName: string, @Query('format') format = 'xlsx') {
    return this.machineryService.sample(moduleName, format);
  }

  @Post('import/:module/preview')
  previewImport(@Param('module') moduleName: string, @Body() body: any) {
    return this.machineryService.previewImport(moduleName, body);
  }

  @Post('import/:module/commit')
  commitImport(@Param('module') moduleName: string, @Body() body: any) {
    return this.machineryService.commitImport(moduleName, body);
  }

  @Get(':id')
  detail(@Param('id') id: string) {
    return this.machineryService.detail(id);
  }

  @Post()
  create(@Body() body: any) {
    return this.machineryService.create(body);
  }

  @Put(':id')
  update(@Param('id') id: string, @Body() body: any) {
    return this.machineryService.update(id, body);
  }

  @Delete(':id')
  delete(@Param('id') id: string) {
    return this.machineryService.delete(id);
  }
}
