import { Controller, Get, Post, Patch, Delete, Param, Body } from '@nestjs/common';
import { ProtectedMutation } from '../../common/audit/protected-mutation.decorator';
import { ProductService } from './product.service';
import { CreateProductDto } from './dto/create-product.dto';
import { UpdateProductDto } from './dto/update-product.dto';

@Controller('products')
export class ProductController {
  constructor(private readonly productService: ProductService) {}

  @Post()
  @ProtectedMutation('product:create', {}, { action: 'product.create', entityType: 'product' })
  create(@Body() dto: CreateProductDto) {
    return this.productService.create(dto);
  }

  @Get()
  findAll() {
    return this.productService.findAll();
  }

  @Get('overview')
  findAllWithChildren() {
    return this.productService.findAllWithChildren();
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.productService.findOne(id);
  }

  @Patch(':id')
  @ProtectedMutation('product:edit', { productIdParam: 'id' }, {
    action: 'product.update',
    entityType: 'product',
    entityIdParam: 'id',
    productIdParam: 'id',
  })
  update(@Param('id') id: string, @Body() dto: UpdateProductDto) {
    return this.productService.update(id, dto);
  }

  @Delete(':id')
  @ProtectedMutation('product:delete', { productIdParam: 'id' }, {
    action: 'product.delete',
    entityType: 'product',
    entityIdParam: 'id',
    productIdParam: 'id',
  })
  remove(@Param('id') id: string) {
    return this.productService.remove(id);
  }
}
