#!/usr/bin/env php
<?php
/**
 * Cron: marcar como past_due los tenants cash con current_period_end vencido.
 * Ejecutar diariamente a las 01:00.
 *
 * Crontab:
 *   0 1 * * * php /var/www/html/cron/expire_cash.php >> /var/log/vale_cron.log 2>&1
 *
 * En Cloud Run Jobs:
 *   schedule: "0 1 * * *"
 *   command: ["php", "/var/www/html/cron/expire_cash.php"]
 */

if (PHP_SAPI !== 'cli') {
    http_response_code(403);
    exit("Solo desde CLI\n");
}

require_once dirname(__DIR__) . '/app/db.php';
require_once dirname(__DIR__) . '/app/services/billing.php';

$db      = DB::connect();
$expired = BillingService::expirarCashVencidos($db);

$ts = date('Y-m-d H:i:s');
echo "[$ts] expire_cash: $expired tenants marcados past_due\n";
