import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';
import { ProtectedMutation } from '../../common/audit/protected-mutation.decorator';
import { CreateMemberDto } from './dto/create-member.dto';
import { UpdateMemberDto } from './dto/update-member.dto';
import { MemberService } from './member.service';

@Controller('members')
export class MemberController {
  constructor(private readonly memberService: MemberService) {}

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

  @Post()
  @ProtectedMutation('member:create', {}, { action: 'member.create', entityType: 'member' })
  create(@Body() dto: CreateMemberDto) {
    return this.memberService.create(dto);
  }

  @Patch(':id')
  @ProtectedMutation('member:edit', {}, {
    action: 'member.update',
    entityType: 'member',
    entityIdParam: 'id',
  })
  update(@Param('id') id: string, @Body() dto: UpdateMemberDto) {
    return this.memberService.update(id, dto);
  }

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