<?php

/**
 * Example: Full Configuration for Auto-Discovered Job
 * 
 * The recurringJob property can be either:
 * 1. An integer for simple interval setup
 * 2. An array for full configuration
 */

namespace console\jobs;

use Yii;
use yii\base\BaseObject;

class UpdateOrders extends BaseObject implements \common\components\Queue\JobInterface
{
    /**
     * Simple form: just the interval in seconds
     */
    public $recurringJob = 900; // Every 15 minutes
    
    // ... rest of class ...
}

// ============================================

class AnotherJob extends BaseObject implements \common\components\Queue\JobInterface
{
    /**
     * Advanced form: full configuration array
     * 
     * Options:
     * - interval (int): Seconds between runs (required if simple form used)
     * - queue (string): Queue component ('queue', 'mailqueue', etc)
     * - name (string): Human-readable job name for tracking
     * - ttr (int): Time-to-reserve in seconds (max execution time)
     * - enabled (bool): Enable/disable this recurring job
     * - checkDuplicates (bool): Prevent queuing duplicates on restart
     * - maxRetries (int): Retry attempts on failure
     * - params (array): Constructor parameters for the job
     */
    public $recurringJob = [
        'interval' => 3600,              // Run every hour
        'queue' => 'mailqueue',          // Use mailqueue component
        'name' => 'Email Processor',     // Custom display name
        'ttr' => 600,                    // Max runtime: 10 minutes
        'enabled' => true,                // Enable this job
        'checkDuplicates' => true,       // Prevent duplicates
        'maxRetries' => 3,               // Retry 3 times
        'params' => [
            // Constructor parameters if needed
            'batchSize' => 100,
            'priority' => 'high',
        ],
    ];
    
    // Constructor accepts the params
    public $batchSize = 50;
    public $priority = 'normal';
    
    public function execute($queue)
    {
        Yii::info("Processing {$this->batchSize} items", __METHOD__);
    }
}
