<?php

namespace App\Http\Resources\Mobile\Supervisor;

use Illuminate\Http\Resources\Json\JsonResource;

class SupervisorProjectResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        return [
            "id"                =>  $this->id, 
            "countTimesheet"    =>  $this->timesheets_count,
            "project"           => 
            [
                "id"            =>  $this->project->id          ?? null, 
                "name"          =>  $this->project->name        ?? null, 
                "clockIn"       =>  $this->project->clock_in    ?? null,
                "clockOut"      =>  $this->project->clock_out   ?? null,
                "dateStart"     =>  $this->project->date_start  ?? null,
                "dateEnd"       =>  $this->project->date_end    ?? null,
                "company"       =>
                [
                    'id'        =>  $this->project->company->id     ?? null,
                    'name'      =>  $this->project->company->name   ?? null
                ]
            ]
        ];
    }
}
