<?php

namespace App\Http\Resources\Frontend;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class FrontendUserResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        $teacherContext = method_exists($this->resource, 'teacherSessionContext')
            ? $this->resource->teacherSessionContext()
            : ['class_section_id' => null, 'class_section_name' => null];

        return [
            'firstname' => $this->firstname ?? null,
            'lastname' => $this->lastname ?? null,
            'class_section_id' => $teacherContext['class_section_id'],
            'class_section_name' => $teacherContext['class_section_name'],
        ];
    }
}
