<?php
declare(strict_types=1);

namespace CronJobs;

use App\Core\Database;
use App\Core\Logger;

/**
 * Daily: flags expired batches and alerts near-expiry items.
 */
class ExpiryAlertJob
{
    private Database $db;
    public function __construct(Database $db) { $this->db = $db; }

    public function shouldRun(): bool
    {
        return true; // Runs daily
    }

    public function run(): array
    {
        // Bootstrap the app for service access
        $app = \App\Core\App::getInstance();

        $expired = \App\Modules\Inventory\Services\BatchService::flagExpiredBatches();
        $nearExpiry = \App\Modules\Inventory\Services\BatchService::alertNearExpiry(30);

        Logger::info("Expiry alert job: {$expired} expired, {$nearExpiry} near-expiry batches flagged");

        return [
            'expired_flagged' => $expired,
            'near_expiry_alerted' => $nearExpiry,
        ];
    }
}
