import { generateOTP } from '../utils/otp.js'
import { sendMockOtpMail } from '../utils/mailer.js'
import { saveOtp, verifyOtp, removeOtp } from '../utils/redis.js'
import { sendError } from '../utils/response.js'

export class OtpService {
  async sendOtp(email) {
    try {
      const otp = generateOTP()
      await saveOtp(email, otp)
      await sendMockOtpMail(email, otp)
      return { email, otp}
    } catch (error) {
      return sendError('ไม่สามารถส่ง OTP ได้', 'Failed to send OTP')
    }
  }
}
