import { Body, Controller, Get, Param, Post } from '@nestjs/common';
import { MeetingInviteService } from './services/meeting-invite.service';
import { RedeemInviteDto } from './dto/redeem-invite.dto';
import { Public } from './../common/guards/decorators/public.decorator';
/**
 * PUBLIC — must be excluded from the global JwtAuthGuard.
 *
 * The whole point of an invite link is that the recipient has no account.
 * Access is granted by the token, and by the one-time code when the invite
 * scope is VERIFIED.
 *
 * In app.module.ts, if you use a global APP_GUARD, mark these routes public
 * with whatever decorator your guard honours, e.g. @Public().
 */
@Public()
@Controller('j')
export class JoinController {
  constructor(private readonly invites: MeetingInviteService) {}

  /** What the landing page needs — no secrets, no full meeting record */
  @Get(':token')
  peek(@Param('token') token: string) {
    return this.invites.peek(token);
  }

  /** Exchange token (+ OTP) for the room code */
  @Post(':token/redeem')
  redeem(@Param('token') token: string, @Body() dto: RedeemInviteDto) {
    return this.invites.redeem(token, dto);
  }

  @Post(':token/resend-otp')
  resend(@Param('token') token: string) {
    return this.invites.resendOtp(token);
  }
}
