$this->id, 'event_id' => $this->event_id, 'first_name' => $this->first_name, 'last_name' => $this->last_name, 'date_of_birth' => $this->date_of_birth?->toDateString(), 'full_name' => $this->full_name, 'email' => $this->email, 'phone' => $this->phone, 'status' => $this->status, 'is_blacklisted' => $this->is_blacklisted, 'admin_notes' => $this->admin_notes, 'remarks' => $this->remarks, 'custom_fields' => $this->custom_fields, 'created_at' => $this->created_at->toIso8601String(), 'crowd_type' => new CrowdTypeResource($this->whenLoaded('crowdType')), 'company' => new CompanyResource($this->whenLoaded('company')), 'has_user_account' => (bool) $this->user_id, 'user_account' => $this->when($this->user_id && $this->relationLoaded('user') && $this->user, fn () => [ 'id' => $this->user->id, 'email' => $this->user->email, 'full_name' => $this->user->full_name, ]), 'pending_identity_match' => $this->when( $this->relationLoaded('pendingIdentityMatch') && $this->pendingIdentityMatch, function () { $match = $this->pendingIdentityMatch; return [ 'match_id' => $match->id, 'matched_user' => [ 'id' => $match->matchedUser->id, 'first_name' => $match->matchedUser->first_name, 'last_name' => $match->matchedUser->last_name, 'full_name' => $match->matchedUser->full_name, 'email' => $match->matchedUser->email, 'date_of_birth' => $match->matchedUser->date_of_birth?->toDateString(), ], 'matched_on' => $match->matched_on->value, 'matched_on_label' => $match->matched_on->label(), 'confidence' => $match->confidence->value, 'confidence_label' => $match->confidence->label(), 'match_details' => $match->match_details, ]; } ), 'crowd_list_pivot' => $this->when( $this->pivot && $this->pivot->added_at, fn () => [ 'added_at' => $this->pivot->added_at, 'added_by_user_id' => $this->pivot->added_by_user_id, ] ), 'field_values' => PersonFieldValueResource::collection($this->whenLoaded('fieldValues')), 'section_preferences' => PersonSectionPreferenceResource::collection($this->whenLoaded('sectionPreferences')), 'tags' => $this->when( $this->user_id && $this->relationLoaded('user'), function () { $orgId = $this->event?->organisation_id; if (!$orgId || !$this->user) { return []; } return UserOrganisationTagResource::collection( $this->user->organisationTags() ->where('organisation_id', $orgId) ->with('personTag') ->get() ); }, [] ), ]; } }