<?php

namespace Tests\Unit\Services\Notifications;

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

class NotificationCleanupServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_cleanup_expired_soft_deletes_rows(): void
    {
        DB::table('notifications')->insert([
            [
                'id' => 1,
                'title' => 'Old',
                'message' => 'Old',
                'target_group' => 'all',
                'delivery_channels' => json_encode(['in_app']),
                'priority' => 1,
                'status' => 'sent',
                'scheduled_at' => now()->subDays(2),
                'expires_at' => now()->subDay(),
                'school_year' => '2024-2025',
                'semester' => 'Spring',
            ],
            [
                'id' => 2,
                'title' => 'Active',
                'message' => 'Active',
                'target_group' => 'all',
                'delivery_channels' => json_encode(['in_app']),
                'priority' => 1,
                'status' => 'sent',
                'scheduled_at' => now()->subDay(),
                'expires_at' => now()->addDay(),
                'school_year' => '2024-2025',
                'semester' => 'Spring',
            ],
        ]);

        $service = new NotificationCleanupService();
        $deleted = $service->cleanupExpired();

        $this->assertSame(1, $deleted);
        $this->assertSoftDeleted('notifications', ['id' => 1]);
        $this->assertDatabaseHas('notifications', ['id' => 2]);
    }
}
