import { Controller, Get, Post, Patch, Delete, Param, Body, Query } from '@nestjs/common';
import { RequirementService } from './requirement.service';
import { CreateRequirementDto } from './dto/create-requirement.dto';
import { UpdateRequirementDto } from './dto/update-requirement.dto';
import { UpdateRequirementStatusDto } from './dto/update-requirement-status.dto';

@Controller('products/:productId/requirements')
export class RequirementController {
  constructor(private readonly requirementService: RequirementService) {}

  @Post()
  create(
    @Param('productId') productId: string,
    @Body() dto: CreateRequirementDto,
  ) {
    return this.requirementService.create(productId, dto);
  }

  @Get()
  findAll(
    @Param('productId') productId: string,
    @Query('status') status?: string,
  ) {
    return this.requirementService.findAll(productId, status);
  }

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

  @Patch(':id')
  update(
    @Param('productId') productId: string,
    @Param('id') id: string,
    @Body() dto: UpdateRequirementDto,
  ) {
    return this.requirementService.update(productId, id, dto);
  }

  @Patch(':id/status')
  updateStatus(
    @Param('productId') productId: string,
    @Param('id') id: string,
    @Body() dto: UpdateRequirementStatusDto,
  ) {
    return this.requirementService.updateStatus(productId, id, dto.status);
  }

  @Delete(':id')
  remove(
    @Param('productId') productId: string,
    @Param('id') id: string,
  ) {
    return this.requirementService.remove(productId, id);
  }
}
