<?php

namespace App\Http\Resources\Company\WorkerRequest;

use App\Models\WorkAreas;

use App\Http\Resources\Admin\CompanyResource;
use App\Http\Resources\Miscellaneous\Expertise\ExpertiseResource;
use App\Http\Resources\Miscellaneous\ZipCodeRange\ZipCodeRangeResource;
use App\Http\Resources\WorkArea\WorkAreaResource;

use Illuminate\Http\Resources\Json\JsonResource;

class WorkerRequestManagementResource 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 [
            //! MAIN 
            'id'                                     => $this->id,
            'experience'                             => $this->experience,
            'status'                                 => $this->status,
            'zipCodeRadius'                          => $this->zip_code_radius,
            'dateStart'                              => $this->date_start,
            'dateEnd'                                => $this->date_end,
            'description'                            => $this->description,
            'onSuccessAction'                        => $this->on_success_action,
            'numberOfApplicantsToBeBorrowed'         => $this->number_of_applicants_to_be_borrowed,
            'numberOfApplicantsSuccessfullyBorrowed' => $this->number_of_applicants_successfully_borrowed,
            'createdAt'                              => $this->created_at,
            'updatedAt'                              => $this->updated_at,

            //! RELATIONSHIPS
            // 'company'    => CompanyResource::make($this->whenLoaded('company')),
            'applicationsCount' => $this->whenLoaded('applications', $this->applications_count, 0),
            'company'           => $this->whenLoaded(
                    'company', 
                            [
                                        'id'   => $this->company->id, 
                                        'name' => $this->company->name 
                                    ]
                                ),
            'expertise'     =>  ExpertiseResource::make($this->whenLoaded('expertise')),
            'workAreas'     =>  WorkAreaResource::collection($this->whenLoaded('workAreas')),
            'zipCodeRange'  =>  ZipCodeRangeResource::make(
                                    $this->whenLoaded(
                                    'zipCodeRange', 
                                    )
                                )
        ];
    }
}
