function array = arrow2matlab(unpacked_array, preserveVariableNames, arrowTypeConversionOptions, assembleTable)
%MATLAB.IO.ARROW.ARROW2MATLAB
%   Construct a native MATLAB array from a struct/primitve array generated by the
%   Arrow-MATLAB MEX layer.
%   Also does UTF-8 to UTF-16 conversion for string types, and bit-unpacking for
%   logical types.

%   Copyright 2018-2021 The MathWorks, Inc.

% If preserveVariableNames is not provided as input, assume that we need
% backwards compatible behavior.

if nargin < 2
    preserveVariableNames = false;
end

if nargin < 3
    arrowTypeConversionOptions = matlab.io.internal.arrow.conversion.ArrowTypeConversionOptions();
end

if nargin < 4
    assembleTable = true;
end

try
    opts = matlab.io.arrow.internal.Arrow2MatlabOptions(PreserveVariableNames=preserveVariableNames, ArrowTypeConversionOptions=arrowTypeConversionOptions);
    array = matlab.io.arrow.internal.arrow2matlab(unpacked_array, opts, assembleTable);
catch ME
    throw(ME);
end

end
