<?php

namespace App\Http\Requests\Api;

use App\Enums\PermissionSlug;
use App\Models\Unit;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class LookupBookingUnitRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->hasPermission(PermissionSlug::BookingsCreate) === true
            || $this->user()?->hasPermission(PermissionSlug::BookingsView) === true;
    }

    /**
     * @return array<string, ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'unit_id' => ['required', 'integer', Rule::exists(Unit::class, 'id')],
            'unit_number' => ['required', 'string', 'max:50'],
        ];
    }
}
