<?php

namespace App\Http\Requests\Photobooth;

use Illuminate\Foundation\Http\FormRequest;

class PhotoboothConnectRedeemRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'code' => ['required', 'string', 'size:6', 'regex:/^\d{6}$/'],
        ];
    }

    protected function prepareForValidation(): void
    {
        $code = preg_replace('/\D+/', '', (string) $this->input('code'));

        $this->merge([
            'code' => $code,
        ]);
    }
}
