<?php

namespace App\Http\Resources;

use App\Models\Profile;
use App\Models\Applicant;
use Illuminate\Http\Request;
use App\Http\Resources\JobResource;
use Illuminate\Http\Resources\Json\JsonResource;

class JobResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'user_id' => $this->user_id,
            'user_kyc' => Profile::where('user_id', $this->user_id)->first()->kyc,
            'name' => $this->name,
            'description' => $this->description,
            'accommodation' => $this->accommodation,
            'working_days' => $this->working_days,
            'working_hours' => $this->working_hours,
            'image' => $this->image,
            'salary' => $this->salary,
            'address' => $this->address,
            'location' => $this->location,
            'recommended_age' => $this->recomended_age,
            'skills' => $this->getFormattedSkillsAttribute(),
            'parameters' => $this->getFormattedParametersAttribute(),
            'applicant' => Applicant::where('job_id', $this->id)->count(),
            'applicants' => $this->getFormattedApplicantAttribute(),
            'recruit_id' => $this->recruit_id,
        ];
    }
}
