<?php

namespace App\Http\Resources\JobOffers;

use App\Helpers\Backoffice\MediaHelper;
use App\Http\Resources\CountryResource;
use App\Http\Resources\Specialisations\SpecialisationResource;
use Illuminate\Http\Resources\Json\JsonResource;

class JobOfferResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */

    public function toArray($request)
    {
        $out = [
            'id' => $this->id,
            'profileId' => $this->company_profile_id,
            'company' => $this->companyProfile ? $this->companyProfile->company_name : null,
            'companyImage' => MediaHelper::getCompanyImageUrl($this->companyProfile?->company_image, '600x'),
            'title' => $this->title,
            'subtitle' => $this->subtitle,
            'content' => $this->content,
            'country' => $this->country ? new CountryResource($this->country) : null,
            'createdAt' => $this->created_at,
            'updatedAt' => $this->updated_at,
            'activeUntil' => $this->active_until,
            'contactPerson' => $this->contact_person,
            'contactByEmail' => $this->contact_by_email,
            'contactByLetter' => $this->contact_by_letter,
            'contactUrl' => $this->contact_url,
            'contactEmail' => $this->contact_email,
            'contactName' => $this->contact_name,
            'contactAddress' => $this->contact_address,
            'contactPostalCode' => $this->contact_postal_code,
            'contactCity' => $this->contact_city,
            'status' => $this->status,
            'specialisations' => SpecialisationResource::collection($this->specialisations),
        ];

        return $out;
    }
}
