<?php

namespace App\Console\Commands;

use App\Services\TenantAnnouncements\TenantAnnouncementService;
use Illuminate\Console\Command;

class DispatchTenantAnnouncements extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'tenant-announcements:dispatch';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Dispatch scheduled tenant announcements and queue email notifications';

    /**
     * Execute the console command.
     */
    public function handle(TenantAnnouncementService $service): int
    {
        $result = $service->process();

        $this->info(sprintf(
            'Announcements: %d activated, %d archived, %d emails queued.',
            $result['activated'],
            $result['archived'],
            $result['queued'],
        ));

        return Command::SUCCESS;
    }
}
