<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Auth;

class MilestoneWIthMiltestoneProgressResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $userId = $request->route('user_id');
        if(!$userId){
            $userId = Auth::user()->id;
        }

        return [
            'id' => $this->id,
            'name' => $this->name,
            'description' => $this->description,
            'milestone_progress' => new MilestoneProgressResource($this->progress->where('user_id', $userId)->first()),
        ];
    }
}
