<?php

namespace App\Http\Resources\V2;

use App\Models\Booking;
use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;


class ListDocumentJobResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        if($this->userInfo){
            $this->owner->userInfo = $this->userInfo;
        }

        return [
            'id' => $this->id,
            'reference' => $this->reference,
            'status' => (int) $this->status,
            'document_type' => $this->document_type,
            'owner' => $this->relationLoaded('owner') ? ($this->owner instanceof Booking ? new BookingV2Resource($this->owner) : new CompanyV2Resource($this->owner)) : null,
            'files' => FileV2Resource::collection($this->files),
            'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A')
        ];
    }
}
