<?php

namespace Modules\Employee\Transformers;

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

class DesignationResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'staff_type' => $this->whenLoaded('staffType', function () {
               return $this->staffType->first() ? new StaffTypeResource($this->staffType) : null;
            }),
            'salary_grade' => $this->whenLoaded('salaryGrade', function () {
               return $this->salaryGrade->first() ? new SalaryGradeResource($this->salaryGrade) : null;
            }),
            'status' => $this->status,
        ];
    }
}
