<?php

namespace Tests\Unit\Services\School;

use App\Services\EmailService;
use App\Services\Notifications\UserNotificationDispatchService;
use App\Services\School\EnrollmentEventService;
use Mockery;
use Tests\TestCase;

class EnrollmentEventServiceTest extends TestCase
{
    public function test_admission_under_review_sends_email(): void
    {
        $email = Mockery::mock(EmailService::class);
        $email->shouldReceive('send')->once()->andReturn(true);

        $notifier = Mockery::mock(UserNotificationDispatchService::class);
        $notifier->shouldReceive('notifyUser')->once();

        $service = new EnrollmentEventService($email, $notifier);
        $result = $service->admissionUnderReview([
            'user_id' => 1,
            'email' => 'parent@example.com',
            'firstname' => 'Parent',
            'lastname' => 'User',
        ], [
            ['firstname' => 'Student', 'lastname' => 'One'],
        ]);

        $this->assertTrue($result['ok']);
    }

    public function test_admission_under_review_requires_email(): void
    {
        $email = Mockery::mock(EmailService::class);
        $notifier = Mockery::mock(UserNotificationDispatchService::class);
        $notifier->shouldReceive('notifyUser')->once();

        $service = new EnrollmentEventService($email, $notifier);
        $result = $service->admissionUnderReview([
            'user_id' => 1,
            'firstname' => 'Parent',
            'lastname' => 'User',
        ], []);

        $this->assertFalse($result['ok']);
    }
}
