<?php

namespace Tests\Unit\Services\Administrator;

use App\Services\Administrator\AdministratorAbsenceService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\Request;
use Mockery;
use Tests\TestCase;

class AdministratorAbsenceServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_submit_requires_reason(): void
    {
        $shared = Mockery::mock(\App\Services\Administrator\AdministratorSharedService::class);
        $shared->shouldReceive('getSemester')->andReturn('Fall');
        $shared->shouldReceive('getSchoolYear')->andReturn('2025-2026');
        $shared->shouldReceive('allowedAbsenceDates')->andReturn(['2025-01-05']);

        $service = new AdministratorAbsenceService(
            $shared,
            new \App\Models\User(),
            new \App\Models\StaffAttendance(),
            new \App\Services\SemesterRangeService(new \App\Services\Semesters\SemesterConfigService()),
            Mockery::mock(\App\Libraries\StaffTimeOffLinkService::class)
        );

        $request = Request::create('/absences', 'POST', ['dates' => ['2025-01-05']]);
        $result = $service->submit($request, 1);

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