<?php

declare(strict_types=1);

namespace App\Http\Resources;

use App\Models\ProjectRequest;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class ProjectRequestResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'payload' => $this->payload,
            'status' => $this->status,
            'status_label' => ProjectRequest::statusOptions()[(string) $this->status] ?? $this->status,
            'admin_note' => $this->admin_note,
            'producer_id' => $this->producer_id,
            'project_id' => $this->project_id,
            'created_by' => $this->created_by,
            'reviewed_by' => $this->reviewed_by,
            'reviewed_at' => $this->reviewed_at?->toISOString(),
            'created_at' => $this->created_at?->toISOString(),
            'updated_at' => $this->updated_at?->toISOString(),
            'producer' => new ProducerResource($this->whenLoaded('producer')),
            'project' => new ProjectSummaryResource($this->whenLoaded('project')),
            'creator' => new UserResource($this->whenLoaded('createdBy')),
            'reviewer' => new UserResource($this->whenLoaded('reviewedBy')),
        ];
    }
}
