<?php

namespace Tests\Unit;

use App\Models\Notification;
use App\Models\User;
use App\Services\NotificationService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class NotificationServiceTest extends TestCase
{
    use RefreshDatabase;

    protected NotificationService $notificationService;

    protected function setUp(): void
    {
        parent::setUp();
        $this->seed();
        $this->notificationService = app(NotificationService::class);
    }

    public function test_can_send_multi_channel_notifications_and_mark_as_read(): void
    {
        $user = User::where('email', 'admin@smkn1gunungagung.sch.id')->first();
        Notification::where('user_id', $user->id)->delete();

        $this->notificationService->notify(
            $user,
            'Test Title',
            'Test Message Content',
            'info',
            ['database', 'email', 'whatsapp']
        );

        $unread = $this->notificationService->getUserUnreadNotifications($user);
        $this->assertCount(1, $unread);
        $this->assertEquals('Test Title', $unread->first()->title);

        // Mark as read
        $this->notificationService->markAllAsRead($user);

        $unreadAfter = $this->notificationService->getUserUnreadNotifications($user);
        $this->assertCount(0, $unreadAfter);
    }
}
