import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';
import { AddProjectMemberDto, RemoveProjectMemberDto, UpdateProjectMemberRoleDto } from './dto/project-member.dto';
import { ProjectMemberService } from './project-member.service';

@Controller('projects/:projectId/members')
export class ProjectMemberController {
  constructor(private readonly projectMemberService: ProjectMemberService) {}

  @Get()
  list(@Param('projectId') projectId: string) {
    return this.projectMemberService.list(projectId);
  }

  @Post()
  add(@Param('projectId') projectId: string, @Body() dto: AddProjectMemberDto) {
    return this.projectMemberService.add({ ...dto, projectId });
  }

  @Patch(':userId/role')
  updateRole(
    @Param('projectId') projectId: string,
    @Param('userId') userId: string,
    @Body() dto: UpdateProjectMemberRoleDto,
  ) {
    return this.projectMemberService.updateRole({ ...dto, projectId, userId });
  }

  @Delete(':userId')
  remove(
    @Param('projectId') projectId: string,
    @Param('userId') userId: string,
    @Body() dto: RemoveProjectMemberDto,
  ) {
    return this.projectMemberService.remove({ ...dto, projectId, userId });
  }
}
