<?php

namespace Tests\Unit\Services\Notifications;

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

class NotificationActiveServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_list_filters_by_target_group(): void
    {
        DB::table('notifications')->insert([
            [
                'id' => 1,
                'title' => 'Parent',
                'message' => 'Message',
                'target_group' => 'parent',
                'delivery_channels' => json_encode(['in_app']),
                'scheduled_at' => now()->subHour(),
                'expires_at' => now()->addHour(),
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'id' => 2,
                'title' => 'Teacher',
                'message' => 'Message',
                'target_group' => 'teacher',
                'delivery_channels' => json_encode(['in_app']),
                'scheduled_at' => now()->subHour(),
                'expires_at' => now()->addHour(),
                'created_at' => now(),
                'updated_at' => now(),
            ],
        ]);

        $service = new NotificationActiveService();
        $result = $service->list('parent');

        $this->assertCount(1, $result['notifications']);
        $this->assertFalse($result['notifications'][0]['isExpired']);
    }
}
