<?php

namespace Tests\Unit\Services\Users;

use App\Services\EmailService;
use App\Services\Users\UserEventService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Mockery;
use Tests\TestCase;

class UserEventServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_handle_new_account_sends_email(): void
    {
        $emailService = Mockery::mock(EmailService::class);
        $emailService->shouldReceive('send')
            ->once()
            ->with(
                'user@example.com',
                'Welcome to Al Rahma Sunday School!',
                Mockery::type('string'),
                'registration'
            )
            ->andReturn(true);

        $service = new UserEventService($emailService);

        $result = $service->handleNewAccountAdded([
            'firstname' => 'Test',
            'lastname' => 'User',
            'email' => 'user@example.com',
        ]);

        $this->assertTrue($result);
    }

    public function test_handle_new_account_requires_email(): void
    {
        $emailService = Mockery::mock(EmailService::class);
        $emailService->shouldNotReceive('send');

        $service = new UserEventService($emailService);
        $result = $service->handleNewAccountAdded([
            'firstname' => 'Test',
            'lastname' => 'User',
        ]);

        $this->assertFalse($result);
    }
}
