<?php

namespace App\Http\Resources;

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

class UserResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'name' => $this->name,
            'email' => $this->email,
            'height' => $this->height,
            'avatarUrl' => $this->avatar_url ? asset(Storage::url($this->avatar_url)) : null,
            'bio' => $this->bio,
            'nutritionGoals' => [
                'calories' => (int) $this->daily_calorie_goal,
                'proteins' => (float) $this->daily_protein_goal,
                'carbs' => (float) $this->daily_carbs_goal,
                'fats' => (float) $this->daily_fats_goal,
            ],
        ];
    }
}
