<?php

namespace App\Http\Requests\Api;

use App\RoomCount;
use App\RoomType;
use Illuminate\Foundation\Http\FormRequest;

class ResidentialComplexesRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
//        $roomCount = RoomCount::query()->pluck('count');
//        $roomTypes = RoomType::query()->pluck('code');
//        $rooms = array_merge($roomCount->toArray(), $roomTypes->toArray());
//
//        $explodedRooms = implode(',', $rooms);

        return [
//            'room_types.*' => 'nullable|in:' . $explodedRooms,
            'cities.*' => 'nullable|exists:cities,id',
            'villages.*' => 'nullable|exists:cities,id',
            'page'=> 'numeric|min:0|max:9999|nullable',
            'districts.*'=> 'nullable|exists:district,id',
            'price.min' => 'nullable|min:0|max:99000000',
            'price.max' => 'nullable|min:0|max:99000000',
            'min_rating' => 'nullable|min:0|max:6',
            'has_promotion' => 'boolean',
            'is_repair' => 'boolean',
            'is_single_sales_department' => 'boolean',
            'is_credit' => 'boolean',
            'is_transport_hub' => 'boolean',
            'space.min' => 'nullable|min:0|max:999',
            'space.max' => 'nullable|min:0|max:999',
            'date.from' => 'nullable|date_format:'.config('app.date_year_format'),
            'date.to' => 'nullable|date_format:'.config('app.date_year_format'),
            'stage_of_construction.*' => 'nullable|exists:stage_of_constructions,id',
            'class_housings.*' => 'nullable|exists:class_housings,id',
            'heating.*' => 'nullable|exists:heatings,id',
            'technology_buildings.*' => 'nullable|exists:technology_buildings,id',
            'other_options.*' => 'nullable|exists:other_options,id',
        ];
    }

    public function all($keys = null)
    {
        $data = parent::all();

        return $data;
    }

    public function messages()
    {
        return [
            'exists' => 'record was not found'
        ];
    }
}
