<?php

namespace App\Http\Resources\Exams;

use Illuminate\Http\Resources\Json\JsonResource;

class ExamDraftResource extends JsonResource
{
    public function toArray($request): array
    {
        return [
            'id' => (int) ($this['id'] ?? 0),
            'teacher_id' => (int) (($this['teacher_id'] ?? $this['author_id'] ?? 0) ?: 0),
            'class_section_id' => (int) ($this['class_section_id'] ?? 0),
            'class_section_name' => $this['class_section_name'] ?? null,
            'semester' => $this['semester'] ?? null,
            'school_year' => $this['school_year'] ?? null,
            'exam_type' => $this['exam_type'] ?? null,
            'draft_title' => $this['draft_title'] ?? null,
            'description' => $this['description'] ?? ($this['author_comment'] ?? null),
            'teacher_file' => $this['teacher_file'] ?? ($this['author_file'] ?? null),
            'teacher_filename' => $this['teacher_filename'] ?? ($this['author_filename'] ?? null),
            'status' => $this['status'] ?? null,
            'admin_id' => $this['admin_id'] ?? ($this['reviewer_id'] ?? null),
            'admin_comments' => $this['admin_comments'] ?? ($this['reviewer_comments'] ?? null),
            'reviewed_at' => $this['reviewed_at'] ?? null,
            'final_file' => $this['final_file'] ?? null,
            'final_filename' => $this['final_filename'] ?? null,
            'final_pdf_file' => $this['final_pdf_file'] ?? null,
            'version' => $this['version'] ?? null,
            'previous_draft_id' => $this['previous_draft_id'] ?? null,
            'is_legacy' => $this['is_legacy'] ?? null,
            'teacher_first' => $this['teacher_first'] ?? null,
            'teacher_last' => $this['teacher_last'] ?? null,
            'admin_first' => $this['admin_first'] ?? null,
            'admin_last' => $this['admin_last'] ?? null,
        ];
    }
}
