import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { OtpVerifierModel } from '../models/otp-verifier.model';
import { OtpVerifierCreateDto } from '../../infrastructure/dto/otp-verification.dto';
import * as moment from 'moment';

@Injectable()
export class OtpVerifierService {
  constructor(
    @InjectRepository(OtpVerifierModel)
    private readonly otpVerifierRepo: Repository<OtpVerifierModel>,
  ) {}

  async create(payload: OtpVerifierCreateDto) {
    const dateNow = moment().valueOf();

    return this.otpVerifierRepo.save({
      ...payload,
      created_at: dateNow,
      updated_at: dateNow,
    });
  }
}
