<?php

namespace App\Http\Requests;

class StoreNewsDraftRequest extends StoreNewsRequest
{
    public function rules(): array
    {
        $rules = parent::rules();
        $rules['submit-state'] = 'required|string|in:draft';

        $rules = array_map(function($rule){
            if( is_array($rule) ){
                return array_map( fn($r) => $r === 'required' ? 'nullable' : $r, $rule);
            }

            return preg_replace(
                ['/\brequired_without\S*/', '/required_with\S*/', '/\brequired\b/'],
                ['nullable',                 'nullable',           'nullable'],
                $rule
            );
        }, $rules );

        return $rules;
    }
}
