<?php

namespace App\Http\Resources;

use App\Enums\GenderEnum;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class ClientProviderBlockResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        $gender = $this->gender ?? $this->provider?->gender?->value;

        return [
            'id'                => $this->id,
            'client_id'         => $this->client_id,
            'provider_id'       => $this->provider_id,
            'provider_name'     => $this->provider_name     ?? $this->provider?->user?->name,
            'gender'            => $gender,
            'gender_label'      => GenderEnum::labelFor($gender),
            'provider_email'    => $this->provider_email    ?? $this->provider?->user?->email,
            'provider_phone'    => $this->provider_phone    ?? $this->provider?->user?->phone,
            'provider_district' => $this->provider_district ?? null,
            'provider_rating'   => $this->provider_rating   ?? null,
            'created_at'        => $this->created_at?->format('Y-m-d H:i'),
            'updated_at'        => $this->updated_at?->format('Y-m-d H:i'),
        ];
    }
}
