<?php

namespace App\Http\Requests\Admin;

use Illuminate\Foundation\Http\FormRequest;

class InternaStoreRequest 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 [
            'id' => 'required',
            'titulo' => [
                'required',
                'min:3'
            ],
            'grupo_interna_id' => 'required',
            'descripcion' => 'required',
            'imagen' =>  'required',
            'secciones' => [
                'required',
                'array',
                'min:1'
            ]
        ];
    }

    protected function prepareForValidation()
    {
        if ($this->input('data.id', null)) {
            $input = $this->input('data.attributes');
            $input = array_merge($input, [
                'id' => $this->input('data.id', null),
            ]);
            $this->replace($input ?? []);
        }
    }
}
