<?php

namespace App\Core\Validator\PropertyPersonPricingPolicy;

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

use App\Core\Validator\BaseValidator;

use Exception;

class PropertyPricingPolicyAdultAddValidator extends BaseValidator
{


    private $setupType ;
    private $valueType ;

    public function __construct
    (


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

    }

    public function rules($params = null)
    {
        return
            [
                'name' => 'nullable',
                'adult_action_type' => 'required|in:DEC,INC',
                'adult' => 'required|numeric',
                'action_type' => 'required|in:DEC,INC',
                'type' => 'required|in:PER,FIX',
                'value' => 'required|numeric',
             //   "checkPricingName" => "accepted"
            ];


    }


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

    public function checkPricingName($params)
    {
        try {
            $isExistPricingName = PropertyPricingPolicyAdult::where('property_id', $params['property_id'])
                ->where('name', $params['name'])
                ->first();

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



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

}
