<?php

namespace App\Http\Requests;

use App\Enums\SpaceBlockType;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreSpaceBlockRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->hasPermission('spaces.block') ?? false;
    }

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return [
            'space_id' => ['required', 'integer', 'exists:spaces,id'],
            'block_type' => ['required', Rule::enum(SpaceBlockType::class)],
            'starts_at' => ['required', 'date'],
            'ends_at' => ['required', 'date', 'after:starts_at'],
            'reason' => ['nullable', 'string'],
        ];
    }
}
