<?php

namespace App\Http\Resources\Results;

use App\Http\Resources\Competitions\CompetitionResource;
use App\Http\Resources\DocumentResource;
use App\Http\Resources\ImageResource;
use Illuminate\Http\Resources\Json\JsonResource;

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

    public function toArray($request)
    {
        return [
            'id' => $this->id,
            // 'competition' => new CompetitionResource($this->competition),
            'result' => new TrackedResultCustomResultResource($this->competition->result),
            'title' => $this->title,
            'subtitle' => $this->subtitle,
            'content' => $this->content,
            'images' => ImageResource::collection($this->images),
            'constructionOwnership' => $this->construction_ownership,
            'street' => $this->street,
            'postalCode' => $this->postal_code,
            'location' => $this->location,
            'magazin' => $this->magazin,
            'finishedDate' => $this->finished_date,
            'updatedDate' => $this->updated_date,
            'pdfDocument' => new DocumentResource($this->pdfDocument),
            'manufacturerGroups' => !empty($this->manufacturerGroups) ? ManufacturerGroupResource::collection($this->manufacturerGroups) : [],
            'executingPartyGroups' => !empty($this->executingPartyGroups) ? ExecutingPartyGroupResource::collection($this->executingPartyGroups) : [],
        ];
    }
}
