<?php

namespace App\Http\Resources;

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

class StageHistoryResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'from_stage' => $this->whenLoaded('fromStage', fn () => $this->fromStage?->name),
            'to_stage' => $this->whenLoaded('toStage', fn () => $this->toStage?->name),
            'changed_at' => $this->changed_at?->toIso8601String(),
            'changed_by' => $this->whenLoaded('changedBy', fn () => $this->changedBy?->name),
            'reason' => $this->reason,
            'notes' => $this->notes,
            'was_overridden' => (bool) $this->was_overridden,
            'unmet_requirements' => $this->unmet_requirements ?? [],
        ];
    }
}
