// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.29.0
// source: users.sql

package queries

import (
	"context"
)

const createUser = `-- name: CreateUser :one
Insert into users (email, password, enabled) values ($1, $2, $3) RETURNING id, password, email, enabled
`

type CreateUserParams struct {
	Email    string
	Password string
	Enabled  bool
}

func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) {
	row := q.db.QueryRow(ctx, createUser, arg.Email, arg.Password, arg.Enabled)
	var i User
	err := row.Scan(
		&i.ID,
		&i.Password,
		&i.Email,
		&i.Enabled,
	)
	return i, err
}

const emailTaken = `-- name: EmailTaken :one
SELECT EXISTS( SELECT 1 FROM users WHERE email = $1 )
`

func (q *Queries) EmailTaken(ctx context.Context, email string) (bool, error) {
	row := q.db.QueryRow(ctx, emailTaken, email)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const getAllUsers = `-- name: GetAllUsers :many
SELECT id, password, email, enabled FROM users
`

func (q *Queries) GetAllUsers(ctx context.Context) ([]User, error) {
	rows, err := q.db.Query(ctx, getAllUsers)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []User
	for rows.Next() {
		var i User
		if err := rows.Scan(
			&i.ID,
			&i.Password,
			&i.Email,
			&i.Enabled,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const getUserByEmail = `-- name: GetUserByEmail :one
SELECT id, password, email, enabled FROM users WHERE email = $1
`

func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error) {
	row := q.db.QueryRow(ctx, getUserByEmail, email)
	var i User
	err := row.Scan(
		&i.ID,
		&i.Password,
		&i.Email,
		&i.Enabled,
	)
	return i, err
}

const getUserById = `-- name: GetUserById :one
SELECT id, password, email, enabled FROM users WHERE id = $1
`

func (q *Queries) GetUserById(ctx context.Context, id int32) (User, error) {
	row := q.db.QueryRow(ctx, getUserById, id)
	var i User
	err := row.Scan(
		&i.ID,
		&i.Password,
		&i.Email,
		&i.Enabled,
	)
	return i, err
}
