<?php

namespace App\Resources;

use Wibiesana\Padi\Core\Resource;

class InternshipResource extends Resource
{
    public function toArray($request): array
    {
        return [
            'id' => $this->id,
            'company_id' => $this->company_id,
            'student_id' => $this->student_id,
            'advisor_teacher_id' => $this->advisor_teacher_id,
            'start_date' => $this->start_date,
            'end_date' => $this->end_date,
            'report_file_path' => $this->report_file_path,
            'advisor_score' => $this->advisor_score,
            'status' => $this->status,
            'attachments' => $this->attachments,

            // Relations
            'company' => $this->whenLoaded('company'),
            'student' => $this->whenLoaded('student'),
            'advisorTeacher' => $this->whenLoaded('advisorTeacher'),

            // Flattened Fields
            'company_name' => $this->company['name'] ?? null,
            'student_name' => $this->student['name'] ?? null,
            'advisorTeacher_name' => $this->advisorTeacher['name'] ?? null,

        ];
    }
}