<?php

namespace App\Console\Commands;

use App\Repositories\UserSubscriptionRepository;
use App\UserSubscription;
use Illuminate\Console\Command;

class ResetSubscriptionWodCounters extends Command {
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'user-subscription:reset-counters';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Resets all active non-bond user subscriptions counters to default.';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        foreach(UserSubscription::all() as $us) {
            if($us->active && $us->pricing && $us->pricing->recharge_weekly) {
                echo "Resetting user subscription with id $us->id...\n";
                UserSubscriptionRepository::resetWodCounters($us);
            }
        }
        echo "Finished.\n";
    }
}
