<?php

namespace App\Http\Requests;

use App\Rules\YoutubeURL;
use Illuminate\Foundation\Http\FormRequest;


class HeroSectionRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, mixed>
     */
    public function rules()
    {
        return [
            'title' => 'required|min:8|max:180',
            'description' => 'required|min:8|max:255',
            'link' => 'required|min:1|max:255',
            'button_text' => 'max:32',
            'background_url' => [
                'required',
                'min:8',
                'max:255',
                new YoutubeURL
            ],
        ];
    }

    public function prepareForValidation()
    {
        $input = $this->input('data.attributes');
        $this->replace($input ?? []);
    }
}
