<?php

namespace App\Http\Resources;

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

class SpecDocumentResource extends JsonResource
{
    public static $wrap = '';

    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    #[\Override]
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'tenant_id' => $this->tenant_id,
            'tenant_name' => $this->tenant?->name,
            'title' => $this->title,
            'version' => $this->version,
            'author_id' => $this->author_id,
            'author' => $this->author?->name,
            'signed_off_at' => $this->signed_off_at,
            'signed_off_by' => $this->signedOffByUser?->name,
            'sign_off_notes' => $this->sign_off_notes,
            'is_signed_off' => $this->isSignedOff(),
            'sections' => SpecDocumentSectionResource::collection($this->whenLoaded('sections')),
            'attachments' => SpecDocumentAttachmentResource::collection($this->whenLoaded('attachments')),
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ];
    }
}
