#!/usr/bin/env bash
# List containers whose contract has not expired yet, next to expire first.
# Output: UUID, email, expires (header + aligned columns).

DB_PATH="/4server/data/contracts.db"

if [ ! -f "$DB_PATH" ]; then
    echo "$(date '+%Y-%m-%d %H:%M:%S') ERROR: database not found at $DB_PATH" >&2
    exit 1
fi

sqlite3 -header -column "$DB_PATH" "
    SELECT UUID AS uuid, email, expires
    FROM containers
    WHERE expires > date('now')
    ORDER BY expires ASC;
"
