import { Body, Controller, Get, Post, Patch, Param, UseGuards } from '@nestjs/common';
import { GuestsService } from './guests.service';
import { JwtAuthGuard } from '../../common/guards/jwt.guard';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { Workspace } from '../../common/decorators/workspace.decorator';

@Controller('guests')
@UseGuards(JwtAuthGuard)
export class GuestsController {
  constructor(private readonly guestsService: GuestsService) {}

  @Get()
  async list(@Workspace('id') wsId: string, @CurrentUser('userId') userId: string) {
    return this.guestsService.list(wsId, userId);
  }

  @Post('invite')
  async invite(
    @Workspace('id') wsId: string,
    @CurrentUser('userId') userId: string,
    @Body() dto: any,
  ) {
    return this.guestsService.invite(wsId, userId, dto);
  }

  @Patch(':userId')
  async updateGuestType(
    @Param('userId') targetUserId: string,
    @Workspace('id') wsId: string,
    @CurrentUser('userId') userId: string,
    @Body() dto: { guest_type: string | null },
  ) {
    return this.guestsService.updateGuestType(wsId, userId, targetUserId, dto);
  }

  @Post(':userId/convert-to-member')
  async convertToMember(
    @Param('userId') targetUserId: string,
    @Workspace('id') wsId: string,
    @CurrentUser('userId') userId: string,
  ) {
    return this.guestsService.convertToMember(wsId, userId, targetUserId);
  }

  @Get(':userId/channels')
  async listGuestChannels(
    @Param('userId') targetUserId: string,
    @Workspace('id') wsId: string,
    @CurrentUser('userId') userId: string,
  ) {
    return this.guestsService.listGuestChannels(wsId, userId, targetUserId);
  }
}