<?php

namespace App\Core\Validator\PropertyPersonPricingPolicy;

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

use App\Core\Validator\BaseValidator;

use Exception;

class PropertyPricingPolicyChildAddValidator extends BaseValidator
{


    public function __construct
    (


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

    }

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


    }

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

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

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



    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());
    }

}
