<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\CheckIn;
use Carbon\Carbon;

class AutoCheckOutCommand extends Command
{
    protected $signature = 'checkout:auto';

    protected $description = 'Otomatis check-out pengguna yang masih aktif pada jam 00:00';

    public function handle()
    {
        $this->info('Memulai proses auto check-out...');

        $affectedRows = CheckIn::whereNull('check_out_time')
        ->update([
            'check_out_time' => Carbon::now(),
            'status' => 'auto-checked-out'
        ]);

        $this->info("Berhasil check-out otomatis {$affectedRows} pengguna.");
    }
}
