import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';
import { ProtectedMutation } from '../../common/audit/protected-mutation.decorator';
import { CreateVersionPlanDto } from './dto/create-version-plan.dto';
import { UpdateVersionPlanDto } from './dto/update-version-plan.dto';
import { VersionPlanService } from './version-plan.service';

@Controller('versions/:versionId/plans')
export class VersionPlanController {
  constructor(private readonly versionPlanService: VersionPlanService) {}

  @Post()
  @ProtectedMutation('version:edit', { versionIdParam: 'versionId' }, {
    action: 'version_plan.create',
    entityType: 'version_plan',
    versionIdParam: 'versionId',
  })
  create(@Param('versionId') versionId: string, @Body() dto: CreateVersionPlanDto) {
    return this.versionPlanService.create(versionId, dto);
  }

  @Get()
  findAll(@Param('versionId') versionId: string) {
    return this.versionPlanService.findAll(versionId);
  }

  @Patch(':id')
  @ProtectedMutation('version:edit', { versionIdParam: 'versionId' }, {
    action: 'version_plan.update',
    entityType: 'version_plan',
    entityIdParam: 'id',
    versionIdParam: 'versionId',
  })
  update(@Param('versionId') versionId: string, @Param('id') id: string, @Body() dto: UpdateVersionPlanDto) {
    return this.versionPlanService.update(versionId, id, dto);
  }

  @Patch(':id/complete')
  @ProtectedMutation('version:edit', { versionIdParam: 'versionId' }, {
    action: 'version_plan.complete',
    entityType: 'version_plan',
    entityIdParam: 'id',
    versionIdParam: 'versionId',
  })
  complete(@Param('versionId') versionId: string, @Param('id') id: string, @Body() dto: UpdateVersionPlanDto) {
    return this.versionPlanService.complete(versionId, id, dto);
  }

  @Delete(':id')
  @ProtectedMutation('version:edit', { versionIdParam: 'versionId' }, {
    action: 'version_plan.delete',
    entityType: 'version_plan',
    entityIdParam: 'id',
    versionIdParam: 'versionId',
  })
  remove(@Param('versionId') versionId: string, @Param('id') id: string) {
    return this.versionPlanService.remove(versionId, id);
  }
}
