package Daje::Database::Model::UsersVerificationCodes;
use Mojo::Base 'Daje::Database::Model::Super::UsersVerificationCodes', -base, -async_await, -signatures;
use v5.42;

# NAME
# ====
#
# Daje::Database::Model::UsersVerificationCodes - Model class
#
# SYNOPSIS
# ========
#
#       use Daje::Database::Model::UsersVerificationCodes;
#
#       my $class = Daje::Database::Model::UsersVerificationCodes->new(db => $db);
#
# DESCRIPTION
# ===========
#
# Daje::Database::Model::UsersVerificationCodes is the model
#
# class that's only generated once. It inherits all
#
# methods from Daje::Database::Model::Super::UsersVerificationCodes#
# This class is meant for non standard methods.
#
# METHODS
# =======
#
#
# LICENSE
# =======
#
# Copyright (C) janeskil1525.
#
# This library is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself.
#
# AUTHOR
# ======
#
# janeskil1525 E<lt>janeskil1525@gmail.com
#

# This file is generated once automatically by Daje Tools 2026-02-01 14:13:34.
# It will not be touched by Daje Tools again.
# <!-- Autogenerated file 2026-02-01 14:13:34 -->


our $VERSION = '0.01';
use Data::Dumper;

sub save_verification_code($self, $mail, $verification_code) {

    my $verification_stmt = qq{
        INSERT INTO users_verification_codes (users_users_fkey, verification_code)
            VALUES((SELECT users_users_pkey FROM users_users WHERE mail = ?), ?)
                ON CONFLICT(users_users_fkey)
        DO UPDATE SET verification_code = ?, moddatetime = NOW()
            RETURNING users_verification_codes_pkey;
    };

    my $login_verification_codes_pkey = $self->db->query(
        $verification_stmt,($mail, $verification_code, $verification_code)
    )->{login_verification_codes_pkey};

    return $login_verification_codes_pkey;
}

sub check_verify($self, $mail, $verification_code) {
    my $verification_stmt = qq{
        SELECT users_verification_codes_pkey FROM users_verification_codes
            WHERE users_users_fkey = (SELECT users_users_pkey FROM users_users WHERE mail = ?) and verification_code = ?;
    };

    my $hash = $self->db->query(
        $verification_stmt,($mail, $verification_code)
    );

    return 1 if $hash && $hash->hash->{users_verification_codes_pkey} > 0;
    return 0;
}

1;

