<?php

namespace App\Console\Commands;

use App\Services\Notifications\NotificationCenterService;
use Illuminate\Console\Command;

class BuildNotificationCenterCommand extends Command
{
    protected $signature = 'dw:notifications {--client=} {--days=7}';

    protected $description = 'API, mail, uyarı, sağlık skoru ve görev kayıtlarından panel içi bildirim üretir.';

    public function handle(NotificationCenterService $notifications): int
    {
        $result = $notifications->buildFromSystem(
            days: (int) $this->option('days'),
            clientId: $this->option('client') ? (int) $this->option('client') : null,
        );

        $this->table(['Kaynak', 'Adet'], collect($result)->map(fn ($count, $key) => [$key, $count])->all());
        $this->info('Toplam: '.array_sum($result).' bildirim kontrol edildi / oluşturuldu.');

        return self::SUCCESS;
    }
}
