<?php

namespace App\Http\Requests\Realty;

use App\Enums\PropertyType;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rules\Enum;

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

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'title' => 'sometimes',
            'code' => 'sometimes',
            'surface' => 'sometimes|numeric',
            'base_price' => 'sometimes|numeric',
            'percentage_initial_fee' => 'sometimes|numeric',
            'property_type' => ['sometimes', new Enum(PropertyType::class)],
            'surface_balcony' => 'nullable',
            'is_balcony' => 'nullable',
            //conexiones
            'number_bathrooms' => [
                'required_if:property_type,' . PropertyType::DEPARTAMENT->name,
            ],

            'number_bedrooms' => [
                'required_if:property_type,' . PropertyType::DEPARTAMENT->name,
            ],
            'floor' => 'sometimes',
            'covered' => [
                'required_if:property_type,' .  PropertyType::PARK->name,
            ],
        ];
    }
}
