<?php

namespace App\Http\Requests\Frontend\Shop;

use Illuminate\Foundation\Http\FormRequest;

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

    /**
     * @return array<string, array<int, string>>
     */
    public function rules(): array
    {
        return [
            'item_id' => ['required', 'integer', 'exists:pw_shop,id'],
            'character_id' => ['required', 'integer'],
            'quantity' => ['required', 'integer', 'min:1', 'max:999'],
        ];
    }

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

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

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