<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class BacklogItemResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'description' => $this->description,
            'type' => $this->type,
            'project_id' => $this->project_id,
            'project' => new ProjectResource($this->whenLoaded('project')),
            'priority' => $this->priority,
            'estimated_effort' => $this->estimated_effort,
            'status' => $this->status,
            'is_archived' => $this->archived_at !== null,
            'archived_at' => $this->archived_at,
            'converted_to_task_id' => $this->converted_to_task_id,
            'converted_task' => new TaskResource($this->whenLoaded('convertedTask')),
            'assigned_sprint_id' => $this->assigned_sprint_id,
            'assigned_sprint' => new SprintResource($this->whenLoaded('assignedSprint')),
            'created_by' => $this->created_by,
            'creator' => new UserResource($this->whenLoaded('creator')),
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ];
    }
}
