<?php

namespace App\Http\Resources;

use App\Models\Company;
use App\Models\Document;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Resources\Json\JsonResource;

class DocumentResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'reference' => $this->reference,
            'status' => (int) $this->status,
            'document_type' => $this->document_type,
            'owner' =>  new CompanyResource($this->whenLoaded('owner')),
            'files' => FileResource::collection($this->files),
            'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A')
        ];
    }
}
