<?php

namespace App\Http\Requests;

use App\Models\Category;
use Illuminate\Foundation\Http\FormRequest;

class CategoryRequest extends FormRequest
{
    public function rules(): array
    {
        return [
            'name' => ['required'],
        ];
    }

    public function authorize(): bool
    {
        if ($this->routeIs('categories.store')) {
            return $this->user()->can('create', Category::class);
        } elseif ($this->routeIs('categories.update')) {
            return $this->user()->can('update', $this->route('category'));
        }

        return false;
    }
}
