<?php

namespace App\Console\Commands;

use App\Services\Care\ProRenewalService;
use Illuminate\Console\Command;

class RenewProSubscriptionsCommand extends Command
{
    protected $signature = 'care:pro-renew';

    protected $description = 'Charge the Ladill wallet for due Care Pro subscriptions (and downgrade after the grace window).';

    public function handle(ProRenewalService $renewals): int
    {
        $due = $renewals->dueOrganizations();
        $this->info("Renewing {$due->count()} due organization(s).");
        $due->each(fn ($organization) => $renewals->renewIfDue($organization));

        return self::SUCCESS;
    }
}
