-- name: GetAllUsers :many
SELECT id, username, first_name, last_name, email, type, enabled, archived
FROM users
WHERE archived = 0
ORDER BY first_name, last_name;

-- name: GetUser :one
SELECT id, username, first_name, last_name, email, type, enabled, archived
FROM users
WHERE id = ?;

-- name: GetUserByUsername :one
SELECT id, username, first_name, last_name, email, type, enabled, archived
FROM users
WHERE username = ? AND archived = 0;

-- name: CreateUser :execresult
INSERT INTO users (
    username, first_name, last_name, email, type, enabled, archived
) VALUES (
    ?, ?, ?, ?, ?, ?, 0);

-- name: UpdateUser :exec
UPDATE users 
SET 
    username = ?,
    first_name = ?,
    last_name = ?,
    email = ?,
    type = ?,
    enabled = ?
WHERE id = ?;

-- name: ArchiveUser :exec
UPDATE users 
SET archived = 1
WHERE id = ?;

-- name: UnarchiveUser :exec
UPDATE users 
SET archived = 0
WHERE id = ?;