<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

/**
 * POST /laundry/scans — cuerpo { qrOrFolio, areaCode } (también acepta snake_case).
 */
class StoreLaundryScanRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    protected function prepareForValidation(): void
    {
        $this->merge([
            'qr_or_folio' => $this->input('qrOrFolio', $this->input('qr_or_folio')),
            'area_code' => $this->input('areaCode', $this->input('area_code')),
            'operator_user_id' => $this->input('operatorUserId', $this->input('operator_user_id')),
        ]);
    }

    /**
     * @return array<string, array<int, string>>
     */
    public function rules(): array
    {
        return [
            'qr_or_folio' => ['required', 'string', 'max:65535'],
            'area_code' => ['required', 'string', 'max:64'],
            'operator_user_id' => ['nullable', 'integer', 'exists:users,id'],
        ];
    }
}
