using Php;

namespace PhpNative {
    public zval array_shift_zval (zval values, string php_file, int php_line) throws Error {
        if (values.get_key_count () == 0) {
            return zval.null_value ();
        }

        string? first_key = values.get_key_at (0);
        zval shifted = first_key == null ? zval.null_value () : (values.get (first_key) ?? zval.null_value ());
        zval remaining = zval.array ();
        for (int i = 1; i < values.get_key_count (); i++) {
            string? key = values.get_key_at (i);
            if (key == null) {
                continue;
            }
            zval? value = values.get (key);
            if (value != null) {
                remaining.append (value);
            }
        }
        values.assign_from (remaining);
        return shifted;
    }
}
