<?php
namespace App\Traits;

trait PatchValidationTrait {
    protected function requirePatchId(mixed $id, string $label = 'ID'): ?int {
        if ($id === null || $id === '' || !ctype_digit((string) $id)) {
            $this->failValidationErrors("{$label} is required and must be a valid integer.");
            return null;
        }
        return (int) $id;
    }

    protected function requirePatchPayload(mixed $payload): ?array {
        if (!is_array($payload) || empty($payload)) {
            $this->failValidationErrors('No data provided for update.');
            return null;
        }
        return $payload;
    }
}
