<?php

namespace App\Core\Validator\OfferCancellationPolicy;

use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Translation\Translator;

use App\Core\Validator\BaseValidator;

class OfferCancellationPolicyCreateValidator extends BaseValidator
{

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

    public function rules($params=null)
    {

        $return =
            [
                "offer_id" => 'required|numeric',
                "has_cancellation_policy" => 'required|boolean',
            ];

        if(fillOnUndefined($params, 'has_cancellation_policy', false) == true)
        {
            $return['cancellation_policy'] = 'required|array|min:1';
            $return['cancellation_policy.*.days_before'] = 'required|numeric';
            $return['cancellation_policy.*.type'] = 'required|in:FIX,PER';
            $return['cancellation_policy.*.value'] = 'required|numeric';
        }

        return $return;
    }

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

}
