<?php

namespace App\Console\Commands;

use App\Services\SubscriptionReminderService;
use Illuminate\Console\Command;

class SendSubscriptionReminders extends Command
{
    protected $signature = 'subscriptions:notify-expiring {--days=7} {--force}';

    protected $description = 'Send automatic subscription payment reminder emails.';

    public function handle(SubscriptionReminderService $service): int
    {
        $days = max(1, (int) $this->option('days'));
        $force = (bool) $this->option('force');

        $this->info("Sending subscription reminders (window={$days}, force=" . ($force ? 'yes' : 'no') . ')...');

        $summary = $service->sendReminders($days, true, $force);

        $this->line('Sent: ' . $summary['sent']);
        $this->line('Skipped: ' . $summary['skipped']);
        $this->line('Failed: ' . $summary['failed']);

        return self::SUCCESS;
    }
}
