<?php

namespace App\Http\Resources\ResidentialComplex;

use App\ResidentialComplex;
use Illuminate\Http\Resources\Json\JsonResource;

class ResidentialComplexCharacteristics extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        $result = [];
        /** @var ResidentialComplex $residentialComplex */
        $residentialComplex = $this;
        $result = [
            'class_housings' => $residentialComplex->class()->get()->toArray(),
            'stage_of_constructions' =>
                $residentialComplex->stageOfConstruction()->first() ?
                    $residentialComplex->stageOfConstruction()->first()->toArray() : "",
            'heating' => $residentialComplex->heating()->get()->toArray(),
            'technology_buildings' => $residentialComplex->technology_building()->get()->toArray(),
            'other_options' => $residentialComplex->other_option()->get()->toArray(),
            'characteristics' => $residentialComplex->residential_complex_characters()->get()->toArray()
        ];

        return $result;
    }
}
