<?php

namespace Tests\Unit\Services\Notifications;

use App\Services\Notifications\NotificationUserListService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class NotificationUserListServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_list_filters_by_read_status(): void
    {
        DB::table('notifications')->insert([
            [
                'id' => 1,
                'title' => 'Unread',
                'message' => 'Message 1',
                'target_group' => 'parent',
                'delivery_channels' => 'in_app',
                'scheduled_at' => now()->subHour(),
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'id' => 2,
                'title' => 'Read',
                'message' => 'Message 2',
                'target_group' => 'parent',
                'delivery_channels' => 'in_app',
                'scheduled_at' => now()->subHours(2),
                'created_at' => now(),
                'updated_at' => now(),
            ],
        ]);

        DB::table('user_notifications')->insert([
            [
                'notification_id' => 1,
                'user_id' => 1,
                'is_read' => 0,
            ],
            [
                'notification_id' => 2,
                'user_id' => 1,
                'is_read' => 1,
            ],
        ]);

        $service = new NotificationUserListService();
        $result = $service->listForUser(1, [
            'read' => true,
            'per_page' => 10,
        ]);

        $this->assertSame(1, $result['pagination']['total']);
    }
}
