-- name: GetAllUsers :many
SELECT id, username FROM users;

-- name: GetUserByID :one
SELECT id, username FROM users WHERE id = ?;

-- name: AddUser :exec
INSERT INTO users (username) VALUES (?);

-- name: GetUserSessions :many
SELECT user_id, username, session_token, created_at, valid_until FROM user_sessions_view WHERE user_id = ?;

-- name: AddUserSession :exec
INSERT INTO user_sessions (user_id, session_token, created_at, valid_until, name)
VALUES (?, ?, ?, ?, ?);

-- name: GetObjectsInStorage :many
SELECT object_id, object_name, storage_location FROM object_storage WHERE storage_location = ?;

-- name: GetUserEvents :many
SELECT event_id, event_name, description, location, start_date, end_date, organizer FROM event_details WHERE organizer = ?;

-- name: GetEventObjects :many
SELECT objects.id, objects.storagespace_id, objects.name, objects.description, objects.serialnumber, objects.created 
FROM objects
JOIN events_objects ON objects.id = events_objects.object_id
WHERE events_objects.event_id = ?;

-- name: AddObject :exec
INSERT INTO objects (storagespace_id, name, description, serialnumber, created)
VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP);

-- name: CreateEvent :exec
INSERT INTO events (user_id, name, description, location, start_date, end_date)
VALUES (?, ?, ?, ?, ?, ?);

-- name: GetEventCheckIns :many
SELECT check_in_id, username, event_name, object_name, datetime, checkin_state FROM check_in_log WHERE event_name = ?;

-- name: AddCheckIn :exec
INSERT INTO check_in (user_id, checkin_event_id, event_id, object_id, checkin_state_id, datetime)
VALUES (?, ?, ?, ?, ?, ?);

-- name: GetObjectAnnotations :many
SELECT id, user_id, object_id, event_id, check_in_id, events_object_id, text, datetime FROM annotations WHERE object_id = ?;

-- name: AddAnnotation :exec
INSERT INTO annotations (user_id, object_id, event_id, check_in_id, events_object_id, text, datetime)
VALUES (?, ?, ?, ?, ?, ?, ?);

-- name: GetEventPictures :many
SELECT id, user_id, storagespace_id, object_id, event_id, check_in_id, path, description, datetime FROM pictures WHERE event_id = ?;

-- name: AddPicture :exec
INSERT INTO pictures (user_id, storagespace_id, object_id, event_id, check_in_id, path, description, datetime)
VALUES (?, ?, ?, ?, ?, ?, ?, ?);

-- name: GetAllStorageSpaces :many
SELECT id, parent, location FROM storagespace;

-- name: GetStorageSpaceByID :one
SELECT id, parent, location FROM storagespace WHERE id = ?;

-- name: GetChildStorageSpaces :many
SELECT id, parent, location FROM storagespace WHERE parent = ?;

-- name: GetObjectsByStorageID :many
SELECT id, storagespace_id, name, description, serialnumber, created 
FROM objects WHERE storagespace_id = ?;
