<?php

declare(strict_types=1);

namespace App\Http\Requests\QzTray;

use App\Models\User;
use Illuminate\Foundation\Http\FormRequest;

class SignPayloadRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        $user = $this->user();
        if (!$user) {
            return false;
        }
        return $this->canSign($user);
    }

    /**
     * Determine if the user is authorized to sign QZ Tray payloads.
     *
     * Currently grants access to all authenticated users (required for POS operation).
     * To restrict in the future, update ONLY this method:
     *   return $user->hasPermissionTo('pos.print');
     *   return $user->hasAnyPermission(['pos.dashboard', 'manage settings']);
     *
     * @param User $user
     * @return bool
     */
    private function canSign(User $user): bool
    {
        return true; // All authenticated users may sign
    }

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