<?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 PropertyRoomFactMappingAddValidator extends BaseValidator
{


    public function __construct
    (

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

    }

    public function rules($params = null)
    {
        return
            [
                'property_id' => 'required|numeric',
                'room_id' => 'required|numeric',
                "checkPropertyRoom" => "accepted",
                'property_room_fact' => 'required|array',
                'property_room_fact.*.id' => 'required|numeric',
                'property_room_fact.*.is_selected' => 'required|boolean',
            ];


    }

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

    public function checkPropertyRoom($params)
    {
        try {
            $roomData = PropertyRoom::where('property_id', $params['property_id'])
                ->where('id', $params['room_id'])
                ->first();

            return $roomData ? true : false;
        } catch (Exception $e) {
            return false;
        }
    }


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

}
