<?php

namespace App\Core\Validator\PropertyRoom;

use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Translation\Translator;
use App\Models\PropertyRoom;

use App\Core\Validator\BaseValidator;

use Exception;

class PropertyRoomAddValidator extends BaseValidator
{


    public function __construct
    (

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

    }

    public function rules($params = null)
    {
        return
            [
                'property_id' => 'required|numeric',
                'name' => 'required',
                "checkName" => "accepted",
                'room_type_id' => 'required|numeric',
                'room_type_count' => 'required|numeric',
                'max_occupancy' => 'required|numeric',
                'max_adult' => 'required|numeric',
                'max_child' => 'required|numeric',
            ];

    }

    public function messages()
    {
        $thisMessages = [];
        return array_merge(parent::messages() , $thisMessages);
    }

    public function checkName($params)
    {
        try {
            $roomRate = PropertyRoom::where('property_id', $params['property_id'])
                ->where('name', $params['name'])
                ->first();
            return $roomRate ? false : true;
        } catch (Exception $e) {
            return false;
        }
    }


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

}
