import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Post,
  Put,
  Query,
} from '@nestjs/common';
import { RawMaterialService } from './raw-material.service';

@Controller('raw-material')
export class RawMaterialController {
  constructor(private readonly rawMaterialService: RawMaterialService) {}

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

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

  @Get('suggestions')
  suggestions(@Query('search') search = '') {
    return this.rawMaterialService.suggestMaterials(search);
  }

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

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

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

  @Get('categories')
  listCategories(@Query() query: Record<string, string>) {
    return this.rawMaterialService.listCategories(query);
  }

  @Post('categories')
  createCategory(@Body() body: any) {
    return this.rawMaterialService.createCategory(body);
  }

  @Put('categories/:id')
  updateCategory(@Param('id') id: string, @Body() body: any) {
    return this.rawMaterialService.updateCategory(id, body);
  }

  @Delete('categories/:id')
  deleteCategory(@Param('id') id: string) {
    return this.rawMaterialService.deleteCategory(id);
  }

  @Get('uoms')
  listUoms(@Query() query: Record<string, string>) {
    return this.rawMaterialService.listUoms(query);
  }

  @Post('uoms')
  createUom(@Body() body: any) {
    return this.rawMaterialService.createUom(body);
  }

  @Put('uoms/:id')
  updateUom(@Param('id') id: string, @Body() body: any) {
    return this.rawMaterialService.updateUom(id, body);
  }

  @Delete('uoms/:id')
  deleteUom(@Param('id') id: string) {
    return this.rawMaterialService.deleteUom(id);
  }

  @Get('vendors')
  listVendors(@Query() query: Record<string, string>) {
    return this.rawMaterialService.listVendors(query);
  }

  @Post('vendors')
  createVendor(@Body() body: any) {
    return this.rawMaterialService.createVendor(body);
  }

  @Put('vendors/:id')
  updateVendor(@Param('id') id: string, @Body() body: any) {
    return this.rawMaterialService.updateVendor(id, body);
  }

  @Delete('vendors/:id')
  deleteVendor(@Param('id') id: string) {
    return this.rawMaterialService.deleteVendor(id);
  }

  @Get('price-history')
  listPriceHistory(@Query() query: Record<string, string>) {
    return this.rawMaterialService.listPriceHistory(query);
  }

  @Get('purchase-orders')
  listPurchaseOrders(@Query() query: Record<string, string>) {
    return this.rawMaterialService.listPurchaseOrders(query);
  }

  @Post('purchase-orders')
  createPurchaseOrder(@Body() body: any) {
    return this.rawMaterialService.createPurchaseOrder(body);
  }

  @Get('purchase-orders/:id')
  getPurchaseOrder(@Param('id') id: string) {
    return this.rawMaterialService.getPurchaseOrder(id);
  }

  @Put('purchase-orders/:id')
  updatePurchaseOrder(@Param('id') id: string, @Body() body: any) {
    return this.rawMaterialService.updatePurchaseOrder(id, body);
  }

  @Delete('purchase-orders/:id')
  deletePurchaseOrder(@Param('id') id: string) {
    return this.rawMaterialService.deletePurchaseOrder(id);
  }

  @Post('purchase-orders/:id/generate')
  generatePurchaseOrder(@Param('id') id: string) {
    return this.rawMaterialService.generatePurchaseOrder(id);
  }

  @Post('purchase-orders/:id/convert-to-stock')
  convertPurchaseOrderToStock(@Param('id') id: string, @Body() body: any) {
    return this.rawMaterialService.convertPurchaseOrderToStock(id, body);
  }

  @Post('purchase-orders/:id/email')
  sendPurchaseOrderEmail(@Param('id') id: string, @Body() body: any) {
    return this.rawMaterialService.sendPurchaseOrderEmail(id, body);
  }

  @Get('settings/raw-material')
  getSettings() {
    return this.rawMaterialService.getSettings();
  }

  @Put('settings/raw-material')
  updateSettings(@Body() body: any) {
    return this.rawMaterialService.updateSettings(body);
  }

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

  @Post()
  createMaterial(@Body() body: any) {
    return this.rawMaterialService.createMaterial(body);
  }

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

  @Delete(':id')
  deleteMaterial(@Param('id') id: string) {
    return this.rawMaterialService.deleteMaterial(id);
  }
}
