<?php

namespace App\Console\Commands;

use App\Services\Users\InactiveUserCleanupService;
use Illuminate\Console\Command;

class DeleteInactiveUsersCommand extends Command
{
    protected $signature = 'users:delete-inactive-users {--minutes=15}';
    protected $description = 'Delete users that are inactive and created more than N minutes ago.';

    public function handle(InactiveUserCleanupService $service): int
    {
        $minutes = (int) $this->option('minutes');
        $result = $service->cleanup($minutes > 0 ? $minutes : 15);

        $this->info(sprintf(
            'Deleted %d inactive users, %d parents rows, %d orphaned user_roles.',
            $result['deleted_users'],
            $result['deleted_parents'],
            $result['deleted_roles']
        ));

        return self::SUCCESS;
    }
}
