import { Controller, Post, Body } from "@nestjs/common";
import { OtpService } from "./otp.service";

@Controller("otp")
export class OtpController {
  constructor(private readonly otpService: OtpService) { }

  @Post("send_OTP")
  async sendOtp(@Body("mobileno") mobileno: string) {
    return this.otpService.sendOtp(mobileno);
  }

  @Post("resend_OTP")
  async resendOtp(
    @Body("requestId") requestId: string,
    @Body("mobileno") mobileno: string
  ) {
    if (!requestId || !mobileno) {
      return {
        status: "failed",
        status_code: 404,
        message: "Request ID and Mobile number are required",
      };
    }
    return this.otpService.resendOtp(requestId, mobileno);
  }

  @Post("verify_OTP")
  async verifyOtp(@Body() body: { requestId: string; otp: any }) {
    const { requestId, otp } = body;
    if (!requestId || !otp) {
      return {
        status: "failed",
        status_code: 404,
        message: "Request ID and OTP are required for verification",
      };
    }
    return this.otpService.verifyOtp(requestId, otp);
  }
}
