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

package sqlc

import (
	"context"

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

const CreateUser = `-- name: CreateUser :one
INSERT INTO users (email, password_hash, first_name, last_name, avatar_url, is_active, is_verified)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id, email, first_name, last_name, avatar_url, is_active, is_verified, last_login, created_at, updated_at
`

type CreateUserParams struct {
	Email        string  `json:"email"`
	PasswordHash string  `json:"passwordHash"`
	FirstName    *string `json:"firstName"`
	LastName     *string `json:"lastName"`
	AvatarUrl    *string `json:"avatarUrl"`
	IsActive     *bool   `json:"isActive"`
	IsVerified   *bool   `json:"isVerified"`
}

type CreateUserRow struct {
	ID         pgtype.UUID      `json:"id"`
	Email      string           `json:"email"`
	FirstName  *string          `json:"firstName"`
	LastName   *string          `json:"lastName"`
	AvatarUrl  *string          `json:"avatarUrl"`
	IsActive   *bool            `json:"isActive"`
	IsVerified *bool            `json:"isVerified"`
	LastLogin  pgtype.Timestamp `json:"lastLogin"`
	CreatedAt  pgtype.Timestamp `json:"createdAt"`
	UpdatedAt  pgtype.Timestamp `json:"updatedAt"`
}

func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateUserRow, error) {
	row := q.db.QueryRow(ctx, CreateUser,
		arg.Email,
		arg.PasswordHash,
		arg.FirstName,
		arg.LastName,
		arg.AvatarUrl,
		arg.IsActive,
		arg.IsVerified,
	)
	var i CreateUserRow
	err := row.Scan(
		&i.ID,
		&i.Email,
		&i.FirstName,
		&i.LastName,
		&i.AvatarUrl,
		&i.IsActive,
		&i.IsVerified,
		&i.LastLogin,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const DeleteUser = `-- name: DeleteUser :exec
DELETE FROM users WHERE id = $1
`

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

const GetUserByEmail = `-- name: GetUserByEmail :one
SELECT id, email, first_name, last_name, avatar_url, is_active, is_verified, last_login, created_at, updated_at
FROM users
WHERE email = $1 LIMIT 1
`

type GetUserByEmailRow struct {
	ID         pgtype.UUID      `json:"id"`
	Email      string           `json:"email"`
	FirstName  *string          `json:"firstName"`
	LastName   *string          `json:"lastName"`
	AvatarUrl  *string          `json:"avatarUrl"`
	IsActive   *bool            `json:"isActive"`
	IsVerified *bool            `json:"isVerified"`
	LastLogin  pgtype.Timestamp `json:"lastLogin"`
	CreatedAt  pgtype.Timestamp `json:"createdAt"`
	UpdatedAt  pgtype.Timestamp `json:"updatedAt"`
}

func (q *Queries) GetUserByEmail(ctx context.Context, email string) (GetUserByEmailRow, error) {
	row := q.db.QueryRow(ctx, GetUserByEmail, email)
	var i GetUserByEmailRow
	err := row.Scan(
		&i.ID,
		&i.Email,
		&i.FirstName,
		&i.LastName,
		&i.AvatarUrl,
		&i.IsActive,
		&i.IsVerified,
		&i.LastLogin,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const GetUserByID = `-- name: GetUserByID :one
SELECT id, email, first_name, last_name, avatar_url, is_active, is_verified, last_login, created_at, updated_at
FROM users
WHERE id = $1 LIMIT 1
`

type GetUserByIDRow struct {
	ID         pgtype.UUID      `json:"id"`
	Email      string           `json:"email"`
	FirstName  *string          `json:"firstName"`
	LastName   *string          `json:"lastName"`
	AvatarUrl  *string          `json:"avatarUrl"`
	IsActive   *bool            `json:"isActive"`
	IsVerified *bool            `json:"isVerified"`
	LastLogin  pgtype.Timestamp `json:"lastLogin"`
	CreatedAt  pgtype.Timestamp `json:"createdAt"`
	UpdatedAt  pgtype.Timestamp `json:"updatedAt"`
}

func (q *Queries) GetUserByID(ctx context.Context, id pgtype.UUID) (GetUserByIDRow, error) {
	row := q.db.QueryRow(ctx, GetUserByID, id)
	var i GetUserByIDRow
	err := row.Scan(
		&i.ID,
		&i.Email,
		&i.FirstName,
		&i.LastName,
		&i.AvatarUrl,
		&i.IsActive,
		&i.IsVerified,
		&i.LastLogin,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const ListUsers = `-- name: ListUsers :many
SELECT id, email, first_name, last_name, avatar_url, is_active, is_verified, last_login, created_at, updated_at
FROM users
ORDER BY created_at DESC
LIMIT $1 OFFSET $2
`

type ListUsersParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

type ListUsersRow struct {
	ID         pgtype.UUID      `json:"id"`
	Email      string           `json:"email"`
	FirstName  *string          `json:"firstName"`
	LastName   *string          `json:"lastName"`
	AvatarUrl  *string          `json:"avatarUrl"`
	IsActive   *bool            `json:"isActive"`
	IsVerified *bool            `json:"isVerified"`
	LastLogin  pgtype.Timestamp `json:"lastLogin"`
	CreatedAt  pgtype.Timestamp `json:"createdAt"`
	UpdatedAt  pgtype.Timestamp `json:"updatedAt"`
}

func (q *Queries) ListUsers(ctx context.Context, arg ListUsersParams) ([]ListUsersRow, error) {
	rows, err := q.db.Query(ctx, ListUsers, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListUsersRow{}
	for rows.Next() {
		var i ListUsersRow
		if err := rows.Scan(
			&i.ID,
			&i.Email,
			&i.FirstName,
			&i.LastName,
			&i.AvatarUrl,
			&i.IsActive,
			&i.IsVerified,
			&i.LastLogin,
			&i.CreatedAt,
			&i.UpdatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const UpdateLastLogin = `-- name: UpdateLastLogin :exec
UPDATE users
SET last_login = CURRENT_TIMESTAMP
WHERE id = $1
`

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

const UpdateUser = `-- name: UpdateUser :one
UPDATE users
SET first_name = $2,
    last_name = $3,
    avatar_url = $4,
    is_active = $5,
    updated_at = CURRENT_TIMESTAMP
WHERE id = $1
RETURNING id, email, first_name, last_name, avatar_url, is_active, is_verified, last_login, created_at, updated_at
`

type UpdateUserParams struct {
	ID        pgtype.UUID `json:"id"`
	FirstName *string     `json:"firstName"`
	LastName  *string     `json:"lastName"`
	AvatarUrl *string     `json:"avatarUrl"`
	IsActive  *bool       `json:"isActive"`
}

type UpdateUserRow struct {
	ID         pgtype.UUID      `json:"id"`
	Email      string           `json:"email"`
	FirstName  *string          `json:"firstName"`
	LastName   *string          `json:"lastName"`
	AvatarUrl  *string          `json:"avatarUrl"`
	IsActive   *bool            `json:"isActive"`
	IsVerified *bool            `json:"isVerified"`
	LastLogin  pgtype.Timestamp `json:"lastLogin"`
	CreatedAt  pgtype.Timestamp `json:"createdAt"`
	UpdatedAt  pgtype.Timestamp `json:"updatedAt"`
}

func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (UpdateUserRow, error) {
	row := q.db.QueryRow(ctx, UpdateUser,
		arg.ID,
		arg.FirstName,
		arg.LastName,
		arg.AvatarUrl,
		arg.IsActive,
	)
	var i UpdateUserRow
	err := row.Scan(
		&i.ID,
		&i.Email,
		&i.FirstName,
		&i.LastName,
		&i.AvatarUrl,
		&i.IsActive,
		&i.IsVerified,
		&i.LastLogin,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}
