<?php

namespace App\Console\Commands;

use App\Mail\NewsletterMail;
use App\Models\Newsletter;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;

class SendNewsletter extends Command
{
    protected $signature = 'newsletter:send {content}';
    protected $description = 'Send newsletter emails to subscribed users';

    public function handle()
    {
        $content = $this->argument('content');
        $newsletters = Newsletter::where('is_subscribed', true)->get();

        foreach ($newsletters as $newsletter) {
            Mail::to($newsletter->email)->send(new NewsletterMail($newsletter, $content));
        }

        $this->info('Newsletter emails sent successfully!');
    }
}
