<?php

namespace Tests\Unit\Services\AttendanceTracking;

use App\Services\AttendanceTracking\AttendanceNotificationWorkflowService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Mockery;
use Tests\TestCase;

class AttendanceNotificationWorkflowServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_record_requires_parent_email(): void
    {
        DB::table('students')->insert([
            'id' => 1,
            'school_id' => 'S1',
            'firstname' => 'Student',
            'lastname' => 'One',
            'age' => 8,
            'gender' => 'Male',
            'photo_consent' => 1,
            'parent_id' => 1,
            'year_of_registration' => '2025',
            'school_year' => '2025-2026',
        ]);

        $parentLookup = Mockery::mock(\App\Services\AttendanceTracking\AttendanceParentLookupService::class);
        $parentLookup->shouldReceive('getPrimaryParentForStudent')->once()->andReturn([]);

        $service = new AttendanceNotificationWorkflowService(
            new \App\Models\Student(),
            new \App\Models\StudentClass(),
            new \App\Models\AttendanceData(),
            new \App\Models\AttendanceTracking(),
            new \App\Models\Configuration(),
            Mockery::mock(\App\Services\AttendanceTracking\AttendanceMailerService::class),
            Mockery::mock(\App\Services\AttendanceTracking\ViolationRuleEngineService::class),
            $parentLookup,
            Mockery::mock(\App\Services\AttendanceTracking\AttendanceEmailComposerService::class),
            Mockery::mock(\App\Services\AttendanceTracking\AttendanceNotificationLogService::class)
        );

        $result = $service->record([
            'student_id' => 1,
            'date' => '2025-01-01',
        ]);

        $this->assertFalse($result['success']);
        $this->assertSame(422, $result['status']);
    }
}
