// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.26.0
// source: remember_2fa.sql

package db

import (
	"context"

	"github.com/jackc/pgx/v5/pgconn"
)

const checkRemember2FAToken = `-- name: CheckRemember2FAToken :one
SELECT EXISTS (SELECT created_at, user_id, code_hash, expires FROM remember_2fa WHERE user_id = $1 AND code_hash = $2 AND expires > $3)
`

type CheckRemember2FATokenParams struct {
	UserID   string
	CodeHash []byte
	Now      int64
}

func (q *Queries) CheckRemember2FAToken(ctx context.Context, arg CheckRemember2FATokenParams) (bool, error) {
	row := q.db.QueryRow(ctx, checkRemember2FAToken, arg.UserID, arg.CodeHash, arg.Now)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const createRemember2FAToken = `-- name: CreateRemember2FAToken :exec
INSERT INTO remember_2fa (created_at,user_id,code_hash,expires) VALUES ($1,$2,$3,$4)
`

type CreateRemember2FATokenParams struct {
	CreatedAt int64
	UserID    string
	CodeHash  []byte
	Expires   int64
}

func (q *Queries) CreateRemember2FAToken(ctx context.Context, arg CreateRemember2FATokenParams) error {
	_, err := q.db.Exec(ctx, createRemember2FAToken,
		arg.CreatedAt,
		arg.UserID,
		arg.CodeHash,
		arg.Expires,
	)
	return err
}

const deleteRemember2FAToken = `-- name: DeleteRemember2FAToken :execresult
DELETE FROM remember_2fa WHERE (user_id = $1 AND code_hash = $2)
`

type DeleteRemember2FATokenParams struct {
	UserID   string
	CodeHash []byte
}

func (q *Queries) DeleteRemember2FAToken(ctx context.Context, arg DeleteRemember2FATokenParams) (pgconn.CommandTag, error) {
	return q.db.Exec(ctx, deleteRemember2FAToken, arg.UserID, arg.CodeHash)
}

const deleteRemember2FATokens = `-- name: DeleteRemember2FATokens :execresult
DELETE FROM remember_2fa WHERE user_id = $1 OR expires < $2
`

type DeleteRemember2FATokensParams struct {
	UserID string
	Now    int64
}

func (q *Queries) DeleteRemember2FATokens(ctx context.Context, arg DeleteRemember2FATokensParams) (pgconn.CommandTag, error) {
	return q.db.Exec(ctx, deleteRemember2FATokens, arg.UserID, arg.Now)
}
