<?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 JobOfferListResource 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,
            'title' => $this->title,
            'content' => $this->content ? mb_substr(strip_tags($this->content), 0, 300) : null,
            'subtitle' => $this->subtitle,
            'country' => $this->country ? new CountryResource($this->country) : null,
            'activeUntil' => $this->active_until,
            'contactName' => $this->contact_name,
            'contactCity' => $this->contact_city,
            'updatedAt' => $this->updated_at,
            'status' => $this->status,
            'specialisations' => SpecialisationResource::collection($this->specialisations),
            'watchlistsIds' => $this->watchlists->pluck('id')->toArray(),
            'isWatchlisted' => $this->watchlists->isNotEmpty(),
        ];

        return $out;
    }
}
