-- name: CreateUser :exec
INSERT INTO users (id, username, name, password_hash, role, avatar_url, state, created_at)
VALUES ($1, $2, $3, $4, $5, '', '', $6);

-- name: GetUserByID :one
SELECT id, username, name, role, avatar_url, state, created_at
FROM users
WHERE id = $1;

-- name: GetUserByUsername :one
SELECT id, username, name, role, avatar_url, state, created_at, password_hash
FROM users
WHERE username = $1;

-- name: ListUsers :many
SELECT id, username, name, role, avatar_url, state, created_at
FROM users
ORDER BY created_at ASC
LIMIT sqlc.arg(row_limit);

-- name: CountAdmins :one
SELECT COUNT(*)::bigint AS count
FROM users
WHERE role = $1;

-- name: GetUserRole :one
SELECT role
FROM users
WHERE id = $1;

-- name: UpdateUserRole :execresult
UPDATE users
SET role = $1
WHERE id = $2;

-- name: UpdateUserState :exec
UPDATE users
SET state = $1
WHERE id = $2;

-- name: UpdateUserStateAndAvatar :exec
UPDATE users
SET state = $1, avatar_url = $2
WHERE id = $3;
