// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.27.0
// source: mfa_queries.sql

package database

import (
	"context"
	"database/sql"
)

const createNewRecoveryCode = `-- name: CreateNewRecoveryCode :one
INSERT INTO recovery_codes (user_id, code_hash)
VALUES ($1, $2)
RETURNING id, created_at
`

type CreateNewRecoveryCodeParams struct {
	UserID   int64
	CodeHash []byte
}

type CreateNewRecoveryCodeRow struct {
	ID        int64
	CreatedAt sql.NullTime
}

func (q *Queries) CreateNewRecoveryCode(ctx context.Context, arg CreateNewRecoveryCodeParams) (CreateNewRecoveryCodeRow, error) {
	row := q.db.QueryRowContext(ctx, createNewRecoveryCode, arg.UserID, arg.CodeHash)
	var i CreateNewRecoveryCodeRow
	err := row.Scan(&i.ID, &i.CreatedAt)
	return i, err
}

const deleteRecoveryCodeByID = `-- name: DeleteRecoveryCodeByID :one
DELETE FROM recovery_codes
WHERE id = $1 AND user_id = $2
RETURNING id
`

type DeleteRecoveryCodeByIDParams struct {
	ID     int64
	UserID int64
}

func (q *Queries) DeleteRecoveryCodeByID(ctx context.Context, arg DeleteRecoveryCodeByIDParams) (int64, error) {
	row := q.db.QueryRowContext(ctx, deleteRecoveryCodeByID, arg.ID, arg.UserID)
	var id int64
	err := row.Scan(&id)
	return id, err
}

const getRecoveryCodesByUserID = `-- name: GetRecoveryCodesByUserID :one
SELECT id, user_id, code_hash, used, created_at, updated_at
FROM recovery_codes
WHERE user_id = $1 AND used = FALSE
`

func (q *Queries) GetRecoveryCodesByUserID(ctx context.Context, userID int64) (RecoveryCode, error) {
	row := q.db.QueryRowContext(ctx, getRecoveryCodesByUserID, userID)
	var i RecoveryCode
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.CodeHash,
		&i.Used,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const markRecoveryCodeAsUsed = `-- name: MarkRecoveryCodeAsUsed :one
UPDATE recovery_codes
SET used = TRUE
WHERE id = $1 AND user_id = $2
RETURNING id, updated_at
`

type MarkRecoveryCodeAsUsedParams struct {
	ID     int64
	UserID int64
}

type MarkRecoveryCodeAsUsedRow struct {
	ID        int64
	UpdatedAt sql.NullTime
}

func (q *Queries) MarkRecoveryCodeAsUsed(ctx context.Context, arg MarkRecoveryCodeAsUsedParams) (MarkRecoveryCodeAsUsedRow, error) {
	row := q.db.QueryRowContext(ctx, markRecoveryCodeAsUsed, arg.ID, arg.UserID)
	var i MarkRecoveryCodeAsUsedRow
	err := row.Scan(&i.ID, &i.UpdatedAt)
	return i, err
}
