<?php

namespace App\Console\Commands;

use App\Services\Attendance\AttendanceAutoPublishJobService;
use Illuminate\Console\Command;

class AttendanceAutoPublishCommand extends Command
{
    protected $signature = 'attendance:auto-publish';
    protected $description = 'Auto-publish attendance days per "second Sunday backward" rule.';

    public function handle(AttendanceAutoPublishJobService $service): int
    {
        $result = $service->run();

        $this->info(sprintf(
            'Auto-publish checked at %s (TZ: %s). Published rows: %d.',
            $result['checked_at'],
            $result['timezone'],
            $result['published']
        ));

        return self::SUCCESS;
    }
}
