import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';
import { VersionService } from './version.service';
import { CreateVersionDto } from './dto/create-version.dto';
import { UpdateVersionDto } from './dto/update-version.dto';

@Controller('products/:productId')
export class VersionController {
  constructor(private readonly versionService: VersionService) {}

  @Post('versions')
  create(@Param('productId') productId: string, @Body() dto: CreateVersionDto) {
    return this.versionService.create(productId, dto);
  }

  @Get('versions')
  findAll(@Param('productId') productId: string) {
    return this.versionService.findAll(productId);
  }

  @Post('projects/:projectId/versions')
  createForProject(
    @Param('productId') productId: string,
    @Param('projectId') projectId: string,
    @Body() dto: CreateVersionDto,
  ) {
    return this.versionService.create(productId, dto, projectId);
  }

  @Get('projects/:projectId/versions')
  findAllForProject(@Param('productId') productId: string, @Param('projectId') projectId: string) {
    return this.versionService.findAll(productId, projectId);
  }

  @Patch('versions/:versionId')
  update(
    @Param('productId') productId: string,
    @Param('versionId') versionId: string,
    @Body() dto: UpdateVersionDto,
  ) {
    return this.versionService.update(productId, versionId, dto);
  }

  @Delete('versions/:versionId')
  remove(@Param('productId') productId: string, @Param('versionId') versionId: string) {
    return this.versionService.remove(productId, versionId);
  }
}
