<?php

namespace App\Http\Requests\Frontend\Voucher;

use Illuminate\Foundation\Http\FormRequest;

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

    /**
     * @return array<string, array<int, string>>
     */
    public function rules(): array
    {
        return [
            'code' => ['required', 'string'],
            'character_id' => ['required', 'integer'],
        ];
    }

    public function getCode(): string
    {
        return strtoupper(trim($this->validated('code')));
    }

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