<?php

namespace Modules\User\Transformers;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Storage;

class PublicMemberProfileResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        $currentEmployment = $this->employments->firstWhere('is_current', true)
            ?? $this->employments->first();

        return [
            'name' => $this->name,
            'member_number' => $this->member_number,
            'member_type' => $this->member_type,
            'status' => $this->status,
            'image_url' => $this->image_url ? Storage::disk('public')->url($this->image_url) : null,
            'company_name' => $currentEmployment?->company_name,
            'verified_at' => now()->toIso8601String(),
        ];
    }
}
