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

package password

import (
	"context"
	"database/sql"
	"fmt"
)

type DBTX interface {
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}

func New(db DBTX) *Queries {
	return &Queries{db: db}
}

func Prepare(ctx context.Context, db DBTX) (*Queries, error) {
	q := Queries{db: db}
	var err error
	if q.createStmt, err = db.PrepareContext(ctx, create); err != nil {
		return nil, fmt.Errorf("error preparing query Create: %w", err)
	}
	if q.getByUserIDStmt, err = db.PrepareContext(ctx, getByUserID); err != nil {
		return nil, fmt.Errorf("error preparing query GetByUserID: %w", err)
	}
	if q.increaseFailedAttemptsStmt, err = db.PrepareContext(ctx, increaseFailedAttempts); err != nil {
		return nil, fmt.Errorf("error preparing query IncreaseFailedAttempts: %w", err)
	}
	if q.resetFailedAttemptsStmt, err = db.PrepareContext(ctx, resetFailedAttempts); err != nil {
		return nil, fmt.Errorf("error preparing query ResetFailedAttempts: %w", err)
	}
	if q.updateStmt, err = db.PrepareContext(ctx, update); err != nil {
		return nil, fmt.Errorf("error preparing query Update: %w", err)
	}
	return &q, nil
}

func (q *Queries) Close() error {
	var err error
	if q.createStmt != nil {
		if cerr := q.createStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing createStmt: %w", cerr)
		}
	}
	if q.getByUserIDStmt != nil {
		if cerr := q.getByUserIDStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing getByUserIDStmt: %w", cerr)
		}
	}
	if q.increaseFailedAttemptsStmt != nil {
		if cerr := q.increaseFailedAttemptsStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing increaseFailedAttemptsStmt: %w", cerr)
		}
	}
	if q.resetFailedAttemptsStmt != nil {
		if cerr := q.resetFailedAttemptsStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing resetFailedAttemptsStmt: %w", cerr)
		}
	}
	if q.updateStmt != nil {
		if cerr := q.updateStmt.Close(); cerr != nil {
			err = fmt.Errorf("error closing updateStmt: %w", cerr)
		}
	}
	return err
}

func (q *Queries) exec(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (sql.Result, error) {
	switch {
	case stmt != nil && q.tx != nil:
		return q.tx.StmtContext(ctx, stmt).ExecContext(ctx, args...)
	case stmt != nil:
		return stmt.ExecContext(ctx, args...)
	default:
		return q.db.ExecContext(ctx, query, args...)
	}
}

func (q *Queries) query(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (*sql.Rows, error) {
	switch {
	case stmt != nil && q.tx != nil:
		return q.tx.StmtContext(ctx, stmt).QueryContext(ctx, args...)
	case stmt != nil:
		return stmt.QueryContext(ctx, args...)
	default:
		return q.db.QueryContext(ctx, query, args...)
	}
}

func (q *Queries) queryRow(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) *sql.Row {
	switch {
	case stmt != nil && q.tx != nil:
		return q.tx.StmtContext(ctx, stmt).QueryRowContext(ctx, args...)
	case stmt != nil:
		return stmt.QueryRowContext(ctx, args...)
	default:
		return q.db.QueryRowContext(ctx, query, args...)
	}
}

type Queries struct {
	db                         DBTX
	tx                         *sql.Tx
	createStmt                 *sql.Stmt
	getByUserIDStmt            *sql.Stmt
	increaseFailedAttemptsStmt *sql.Stmt
	resetFailedAttemptsStmt    *sql.Stmt
	updateStmt                 *sql.Stmt
}

func (q *Queries) WithTx(tx *sql.Tx) *Queries {
	return &Queries{
		db:                         tx,
		tx:                         tx,
		createStmt:                 q.createStmt,
		getByUserIDStmt:            q.getByUserIDStmt,
		increaseFailedAttemptsStmt: q.increaseFailedAttemptsStmt,
		resetFailedAttemptsStmt:    q.resetFailedAttemptsStmt,
		updateStmt:                 q.updateStmt,
	}
}
