<?php

namespace App\Console\Commands;

use App\Models\User;
use App\Models\Verification;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;

#[Signature('users:cleanup-deleted')]
#[Description('Command description')]
class CleanupDeletedUsers extends Command
{
    /**
     * Execute the console command.
     */
    public function handle()
    {
        User::onlyTrashed()
            ->where('deleted_at', '<=', now()->subDays(7))
            ->chunk(100, function ($users) {

                foreach ($users as $user) {
                    $user->anonymize();
                }
            });

        Verification::whereNotNull('verified_at')
            ->orWhere('expires_at', '<', now())
            ->delete();
    }
}
