<?php

namespace App\Http\Requests;

use App\Support\Backoffice\Sanitizer\Traits\SanitizesInput;
use Illuminate\Foundation\Http\FormRequest;

class ProjectRequest extends FormRequest
{
    use SanitizesInput;

    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'name'              => 'required|string|max:255',
            'content'           => 'nullable|string',
            'projectDate'       => 'nullable|date',
            'images'            => 'nullable|array',
            'images.*'          => 'required|array',
            'images.*.id'       => 'nullable|integer|exists:project_images,id',
            'images.*.file'     => 'nullable|file|image|max:4000',
            'images.*.deleted'  => 'nullable|boolean',
            'images.*.position' => 'nullable|integer'
        ];
    }

    /**
     * Filters to be applied to the input.
     *
     * @return array
     */
    public function filters(): array
    {
        return [
            'name'        => "trim|strip_tags|xss_clean",
            'content'     => "trim|frontend_editor_clean|xss_clean",
            'projectDate' => "trim|strip_tags|xss_clean",
        ];
    }
}
