<?php
/**
 * Auto-expire marketplace listings.
 * Marks any active listing whose `expires_at` is in the past as `expired`.
 * Run daily via cron, e.g.:
 *   0 3 * * * /usr/bin/php /path/to/notafilija/cron/expire_listings.php >> /var/log/notafilija_expire.log 2>&1
 */

require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config/app.php';
require_once APP_ROOT . '/config/database.php';
require_once APP_ROOT . '/models/Listing.php';

try {
    $model = new Listing();
    $count = $model->expireOldListings();
    $ts = date('Y-m-d H:i:s');
    echo "[{$ts}] Expired {$count} listing(s)." . PHP_EOL;
} catch (Throwable $e) {
    $ts = date('Y-m-d H:i:s');
    fwrite(STDERR, "[{$ts}] Error expiring listings: " . $e->getMessage() . PHP_EOL);
    exit(1);
}
