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

package repository

import (
	"context"

	"github.com/google/uuid"
)

const findAdminUsers = `-- name: FindAdminUsers :many
SELECT id, email, full_name, password_hash, is_admin, created_at, updated_at, last_login, phone_number, profile_picture, created_by, email_verified, avatar_verified, verified FROM users WHERE created_by = $1
`

func (q *Queries) FindAdminUsers(ctx context.Context, createdBy *uuid.UUID) ([]User, error) {
	rows, err := q.db.Query(ctx, findAdminUsers, createdBy)
	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,
			&i.CreatedBy,
			&i.EmailVerified,
			&i.AvatarVerified,
			&i.Verified,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const findAllUsers = `-- name: FindAllUsers :many
SELECT id, email, full_name, password_hash, is_admin, created_at, updated_at, last_login, phone_number, profile_picture, created_by, email_verified, avatar_verified, verified 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,
			&i.CreatedBy,
			&i.EmailVerified,
			&i.AvatarVerified,
			&i.Verified,
		); 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, created_by, email_verified, avatar_verified, verified 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,
		&i.CreatedBy,
		&i.EmailVerified,
		&i.AvatarVerified,
		&i.Verified,
	)
	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, created_by, email_verified, avatar_verified, verified 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,
		&i.CreatedBy,
		&i.EmailVerified,
		&i.AvatarVerified,
		&i.Verified,
	)
	return i, err
}

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

type InsertUserParams struct {
	Email        string     `json:"email"`
	FullName     string     `json:"full_name"`
	PasswordHash string     `json:"password_hash"`
	IsAdmin      bool       `json:"is_admin"`
	CreatedBy    *uuid.UUID `json:"created_by"`
}

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,
		arg.CreatedBy,
	)
	var id uuid.UUID
	err := row.Scan(&id)
	return id, err
}

const updateLastLogin = `-- name: UpdateLastLogin :exec
UPDATE users
SET last_login = NOW()
WHERE id = $1
`

func (q *Queries) UpdateLastLogin(ctx context.Context, id uuid.UUID) error {
	_, err := q.db.Exec(ctx, updateLastLogin, id)
	return err
}

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

type UpdateProfilePictureParams struct {
	ProfilePicture *string   `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
}

const userVerifyAvatar = `-- name: UserVerifyAvatar :exec
UPDATE users
SET avatar_verified = true
WHERE id = $1
`

func (q *Queries) UserVerifyAvatar(ctx context.Context, id uuid.UUID) error {
	_, err := q.db.Exec(ctx, userVerifyAvatar, id)
	return err
}

const userVerifyComplete = `-- name: UserVerifyComplete :exec
UPDATE users
SET verified = true
WHERE id = $1
`

func (q *Queries) UserVerifyComplete(ctx context.Context, id uuid.UUID) error {
	_, err := q.db.Exec(ctx, userVerifyComplete, id)
	return err
}

const userVerifyEmail = `-- name: UserVerifyEmail :exec
UPDATE users
SET email_verified = true
WHERE id = $1
`

func (q *Queries) UserVerifyEmail(ctx context.Context, id uuid.UUID) error {
	_, err := q.db.Exec(ctx, userVerifyEmail, id)
	return err
}
