<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

use App\Models\TimetableContent;

class TimetableContentValidation extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        if (!auth()->check()) {
            return false;
        }

        if ($this->route('id')) {
            $timetable_content = TimetableContent::findorFail($this->route('id'));
            return $this->user()->can('update', $timetable_content);
        }
        return $this->user()->can('create', TimetableContent::class);
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'tag' => 'required|array',
            'header' => 'string|max:255|nullable',
            'body' => 'string|nullable',
            'style' => 'string|nullable',
            'link' => 'nullable',
            'inline' => 'boolean',
        ];
    }
}
