<?php

namespace App\Core\Validator\PropertyPromotion;

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

use App\Core\Validator\BaseValidator;

use Exception;

class PropertyPromotionAddValidator extends BaseValidator
{


    private $setupType;
    private $valueType;

    public function __construct
    (


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

    }

    public function rules($params = null)
    {
        $return =
            [
                'property_id' => 'required|numeric',
                'promotion_type_id' => 'required|numeric',
                'amount' => 'required|numeric|max:100',
                'days' => 'required|array',

            ];

        $promotionType = PromotionType::where('id' , '=', $params['promotion_type_id'])
            ->first();

        $returnAdd = [];
        if($promotionType['type_code'] == 'PRD'){
           $returnAdd = [
               'start_date' => 'required|date_format:Y-m-d',
               'end_date' => 'required|date_format:Y-m-d',
               'reservation_start_date' => 'required|date_format:Y-m-d',
               'reservation_end_date' => 'required|date_format:Y-m-d',
           ];
        }elseif($promotionType['type_code'] == 'BFD'){

            $returnAdd = [
                'day_before' => 'required|numeric',
            ];

        }
        if($params['min_stay'] != null){
            $returnAdd['min_stay'] = 'numeric';
        }


        return array_merge($return, $returnAdd) ;


    }

    public function messages()
    {
        $thisMessages = [];
        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());
    }

}
