<?php

namespace App\Core\Validator\Property;

use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Translation\Translator;

use App\Core\Validator\BaseValidator;

use Exception;
use Illuminate\Support\Facades\Log;

class PropertyUpdateValidator extends BaseValidator
{

    public function __construct
    (
        Translator $translator,
        Container $container
    )
    {
        parent::__construct($translator, $container);
    }

    public function rules($params = null)
    {
        $return =
            [
                'property_info.name' => 'required|min:3|max:255',
                'property_info.property_type_id' => 'required|numeric',
                'property_info.chain_id' => 'required|numeric',
                'property_info.official_name' => 'nullable|min:3|max:255',
                'property_info.country' => 'required|max:5',
                'property_info.tax_office' => 'nullable|min:3|max:255',
                'property_info.tax_number' => 'nullable|min:2|max:255',
                'property_info.checkin_time' => 'nullable|min:3|max:100',
                'property_info.checkout_time' => 'nullable|min:2|max:100',
                'additional_info' => 'array',
                'additional_info.*.year_construction' => 'nullable|string|max:100',
                'additional_info.*.year_renovation' => 'nullable|string|max:100',

            ];
        if (isset($params['additional_info']['locale_name_language']) || isset($params['additional_info']['locale_name'])) {
            if ( !empty($params['additional_info']['locale_name_language']) || !empty($params['additional_info']['locale_name'])) {
                $return['additional_info.locale_name_language'] = 'required|min:2|max:100';
                $return['additional_info.locale_name'] = 'required';
            }
        }

        return $return;
    }

    public function messages()
    {

        // use example 'validation.input' =>  __('validation_type', ['input' => __('input form language key')]),
        // validation types in baseValidator switch-case block

        $thisMessages = [
            'property_info.name.required' =>  __('error-input-required', ['input' => __('input-property_name')]),
            'property_info.name.min' =>  __('error-input-min', ['input' => __('input-property_name')]),

        ];
        return array_merge(parent::messages() , $thisMessages);
    }


    public function validate(array $params, array $rules = [], array $messages = [], array $customAttributes = [])
    {
        return $this->make($params, $this->rules($params), $this->messages());
    }

}
