function targetObject = create(targetType, varargin)
%TARGET.CREATE    Create a target object.
%   targetObject = TARGET.CREATE(targetType) creates and returns an object
%   of type targetType.
%
%   targetObject = TARGET.CREATE(..., Name, Value) configures the object
%   using one or more name-value pair arguments.
%   Supported argument names include:
%
%   Copy                Create a target object by copying values from the
%                       specified target object.
%
%   IDPrefix            Add a prefix to IDs generated by TARGET.CREATE.
%
%   'propertyName'      Create a target object with the specified property
%                       set to the specified value. If used in conjunction
%                       with 'Copy', the specified value overrides the
%                       value in the copied object.
%
%   See also TARGET.ADD, TARGET.GET, TARGET.REMOVE

%   Copyright 2018-2022 The MathWorks, Inc.

    arguments
        targetType {mustBeTextScalar, target.internal.validators.mustBeTarget}
    end
    arguments (Repeating)
        varargin
    end

    [varargin{:}] = targetframework.internal.user.commandline.matlab.Helpers.unwrapValues(varargin{:});

    % Catch any error thrown by the internal APIs and rethrow it by hiding
    % the stack.
    try
        internalTargetObject = target.internal.create(targetType, varargin{:});
    catch exception
        throwAsCaller(exception);
    end

    targetObject = targetframework.internal.user.commandline.matlab.Helpers.wrapValues(internalTargetObject);
end
