<?php

declare(strict_types=1);

namespace App\Http\Resources\Admin;

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

/**
 * @mixin \App\Models\User
 */
class PendingProfessionalResource extends JsonResource
{
    /**
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'email' => $this->email,
            'phone' => $this->phone,
            'account_type' => $this->account_type?->value,
            'status' => $this->status?->value,
            'created_at' => $this->created_at?->toIso8601String(),
            'professional_profile' => $this->whenLoaded('professionalProfile', function () {
                $p = $this->professionalProfile;

                return $p === null ? null : [
                    'professional_name' => $p->professional_name,
                    'verification_status' => $p->verification_status?->value,
                    'city_id' => $p->city_id,
                ];
            }),
        ];
    }
}
