<?php

namespace Modules\Internal\Transformers;

use Illuminate\Http\Resources\Json\JsonResource;

class DoctorResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request
     * @return array
     */
    public function toArray($request)
    {
        $doctor = [
            'id' => $this->id,
            // 'his_dokter_id' => $this->practitionerRoles->meta,
            'name' => $this->person->name,
            'person_id' => $this->person->id,
            'phone' => $this->person->phone,
            'email' => $this->person->email,
            'gender' => $this->person->gender == "L" ? 'Laki-laki' : 'Perempuan',
            'address' => $this->person->currentAddress->text,
            'organizations' => $this->practitionerRoles->unique('organization_id')->map(function ($practitionerRole) {
                return [
                    'organization_id' => $practitionerRole->organization->id,
                    'organization_name' => $practitionerRole->organization->name,
                ];
            }),
            "specialties" => $this->practitionerRoles->unique('speciality_id')->map(function ($practitionerRole) {
                return [
                    'specialty_id' => $practitionerRole->speciality->id,
                    'specialty_name' => $practitionerRole->speciality->name,
                ];
            }),
            "departemen" => $this->practitionerRoles->map(function ($practitionerRole) {
                return [
                    'departemen_id' => $practitionerRole->meta->DepartemenID,
                ];
            }),
            'education' => $this->meta->education,
            'experience' => $this->meta->work_experience,
            'award' => $this->meta->award,
            'keilmuan' => $this->meta->Keilmuan,
            'tipe_dokter' => $this->meta->tipeDokter,

        ];

        return $doctor;
    }
}
