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

package repository

import (
	"context"

	"github.com/google/uuid"
	"github.com/jackc/pgx/v5/pgtype"
)

const findAllUsers = `-- name: FindAllUsers :many
SELECT id, email, full_name, password_hash, is_admin, created_at, updated_at, last_login, phone_number, profile_picture FROM users
`

func (q *Queries) FindAllUsers(ctx context.Context) ([]User, error) {
	rows, err := q.db.Query(ctx, findAllUsers)
	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.Email,
			&i.FullName,
			&i.PasswordHash,
			&i.IsAdmin,
			&i.CreatedAt,
			&i.UpdatedAt,
			&i.LastLogin,
			&i.PhoneNumber,
			&i.ProfilePicture,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const findUserEmail = `-- name: FindUserEmail :one
SELECT id, email, full_name, password_hash, is_admin, created_at, updated_at, last_login, phone_number, profile_picture FROM users WHERE email = $1 LIMIT 1
`

func (q *Queries) FindUserEmail(ctx context.Context, email string) (User, error) {
	row := q.db.QueryRow(ctx, findUserEmail, email)
	var i User
	err := row.Scan(
		&i.ID,
		&i.Email,
		&i.FullName,
		&i.PasswordHash,
		&i.IsAdmin,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.LastLogin,
		&i.PhoneNumber,
		&i.ProfilePicture,
	)
	return i, err
}

const findUserId = `-- name: FindUserId :one
SELECT id, email, full_name, password_hash, is_admin, created_at, updated_at, last_login, phone_number, profile_picture FROM users WHERE id = $1 LIMIT 1
`

func (q *Queries) FindUserId(ctx context.Context, id uuid.UUID) (User, error) {
	row := q.db.QueryRow(ctx, findUserId, id)
	var i User
	err := row.Scan(
		&i.ID,
		&i.Email,
		&i.FullName,
		&i.PasswordHash,
		&i.IsAdmin,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.LastLogin,
		&i.PhoneNumber,
		&i.ProfilePicture,
	)
	return i, err
}

const insertUser = `-- name: InsertUser :one
INSERT INTO users (
    email, full_name, password_hash, is_admin
) VALUES (
    $1, $2, $3, $4
)
RETURNING id
`

type InsertUserParams struct {
	Email        string `json:"email"`
	FullName     string `json:"full_name"`
	PasswordHash string `json:"password_hash"`
	IsAdmin      bool   `json:"is_admin"`
}

func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) (uuid.UUID, error) {
	row := q.db.QueryRow(ctx, insertUser,
		arg.Email,
		arg.FullName,
		arg.PasswordHash,
		arg.IsAdmin,
	)
	var id uuid.UUID
	err := row.Scan(&id)
	return id, err
}

const updateProfilePicture = `-- name: UpdateProfilePicture :exec
UPDATE users
SET profile_picture = $1
WHERE id = $2
`

type UpdateProfilePictureParams struct {
	ProfilePicture pgtype.Text `json:"profile_picture"`
	ID             uuid.UUID   `json:"id"`
}

func (q *Queries) UpdateProfilePicture(ctx context.Context, arg UpdateProfilePictureParams) error {
	_, err := q.db.Exec(ctx, updateProfilePicture, arg.ProfilePicture, arg.ID)
	return err
}
