*/ public function toArray(Request $request): array { $this->resource->loadMissing(['activeNutritionPlan', 'latestWeightEntry']); $nutritionPlan = $this->activeNutritionPlan; return [ 'id' => $this->id, 'name' => $this->name, 'email' => $this->email, 'locale' => $this->locale, 'emailVerified' => $this->hasVerifiedEmail(), 'emailVerifiedAt' => $this->email_verified_at?->toISOString(), 'height' => $this->height, 'currentWeight' => $this->latestWeightEntry?->weight_kg, 'targetWeight' => $this->target_weight, 'avatarUrl' => $this->avatar_url ? asset(Storage::url($this->avatar_url)) : null, 'bio' => $this->bio, 'role' => $this->role, 'accountVerified' => $this->account_verified_at !== null, 'certificationPurchased' => $this->hasPurchasedCertification(), 'canAnalyzeMeals' => $this->canAnalyzeMeals(), 'analysisAccessLevel' => $this->analysisAccessLevel(), 'trialEndsAt' => $this->analysisAccessLevel() === 'trial' ? $this->subscription_expires_at?->toISOString() : null, 'subscriptionExpiresAt' => $this->subscription_expires_at?->toISOString(), 'subscriptionProductId' => $this->subscription_product_id, 'hasActiveSubscription' => $this->hasActiveSubscription(), 'suspendedAt' => $this->suspended_at?->toISOString(), 'physicalActivityLevel' => $this->physical_activity_level, 'weightGoal' => $this->weight_goal, 'pacePreference' => $this->pace_preference, 'sex' => $this->sex, 'dateOfBirth' => $this->date_of_birth?->toDateString(), 'onboardingStatus' => $this->hasCompletedNutritionOnboarding() ? 'completed' : 'required', 'missingOnboardingFields' => $this->hasCompletedNutritionOnboarding() ? [] : [ 'dateOfBirth', 'sex', 'heightCm', 'weightKg', 'physicalActivityLevel', 'weightGoal', 'pacePreference', ], 'nutritionPlan' => NutritionPlanResource::make($nutritionPlan), 'nutritionGoals' => $nutritionPlan ? [ 'calories' => $nutritionPlan->calories, 'proteins' => $nutritionPlan->proteins, 'carbs' => $nutritionPlan->carbs, 'fats' => $nutritionPlan->fats, ] : null, ]; } }