<?php

namespace Modules\Approval\Transformers;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Modules\Core\Transformers\ActionUserResource;

class ApprovalRequestStepResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'level' => $this->level,
            'status' => $this->status,
            'state' => $this->state(),
            'role' => $this->workflowStep?->role?->title,
            'action_at' => $this->action_at,
            'action_by' => $this->whenLoaded('actor', function () {
                return new ActionUserResource($this->actor);
            }),
            'remarks' => $this->remarks
        ];
    }
}
