import { Controller, Post, Body, Get, Param } from '@nestjs/common';

import {
  BookingVerificationDto,
  VerificationCodeDto,
} from '../dto/booking-verification.dto';
import { VerificationService } from '../../data/services/verification.service';
import { Public } from 'src/core/guards/domain/decorators/unprotected.guard';
import { ApiTags } from '@nestjs/swagger';

@ApiTags('Booking Authentication')
@Public()
@Controller('v1/booking-authentication')
export class BookingAuthenticationController {
  constructor(
    private readonly bookingAuthenticationService: VerificationService,
  ) {}

  @Post('verify')
  async verify(@Body() body: VerificationCodeDto) {
    const verification = await this.bookingAuthenticationService.verify(body);
    const token = await this.bookingAuthenticationService.generateToken(
      verification,
    );
    return {
      message: `Verification successful for ${verification.phone_number}`,
      token,
    };
  }

  @Post('register')
  async register(@Body() body: BookingVerificationDto) {
    const verification = await this.bookingAuthenticationService.register(body);
    return {
      message: `Verification code sent to ${verification.phone_number}`,
    };
  }

  @Get('get-by-phone/:phone_number')
  async getByPhoneNumber(@Param('phone_number') phone_number: string) {
    return this.bookingAuthenticationService.findByPhoneNumber(phone_number);
  }
}
