<?php

namespace App\Http\Requests\Frontend\Service;

use Illuminate\Foundation\Http\FormRequest;

final class ExchangeItemRequest extends FormRequest
{
    public function authorize(): bool
    {
        return auth()->check();
    }

    /**
     * @return array<string, array<int, string>>
     */
    public function rules(): array
    {
        return [
            'role_id' => ['required', 'integer'],
            'item_count' => ['nullable', 'integer', 'min:1'],
        ];
    }

    public function getRoleId(): int
    {
        return (int) $this->validated('role_id');
    }

    public function getItemCount(): ?int
    {
        return $this->has('item_count') ? (int) $this->validated('item_count') : null;
    }
}
