classdef simoptions < matlab.mixin.SetGet & matlab.mixin.Copyable
    %modelpack.simoptions class
    %    modelpack.simoptions properties:
    %       Configuration - Property is of type 'handle'
    %       InitialState - Property is of type 'handle vector'
    %       Outputs - Property is of type 'handle vector'
    %       Description - Property is of type 'ustring'
    %
    
    % Copyright 2000-2023 The MathWorks, Inc.

    properties (Access=protected, SetObservable)
        %VERSION Property is of type 'double'
        Version = 0;
    end

    properties (SetObservable)
        %CONFIGURATION Property is of type 'handle'
        Configuration = [];
        %INITIALSTATE Property is of type 'handle vector'
        InitialState = [];
        %OUTPUTS Property is of type 'handle vector'
        Outputs = [];
        %DESCRIPTION Property is of type 'ustring'
        Description = '';
    end


    events
        StopSim
    end  % events

    methods  % constructor block
        function this = simoptions(model, config, states, outputs)
            % SIMOPTIONS Constructor
            %
            % h = modelpack.simoptions(model)
            %
            % MODEL is a Model object.

            % Create object

            % No argument constructor call
            if nargin == 0
                return
            end

            % Check model argument
            if ~isempty(model) && ~isa(model, 'modelpack.Model')
                error(message('SLControllib:modelpack:errArgumentType', ...
                    'MODEL', 'modelpack.Model' ));
            end

            % Default arguments
            if (nargin < 2 || isempty(config)),  config  = []; end
            if (nargin < 3 || isempty(states)),  states  = []; end
            if (nargin < 4 || isempty(outputs)), outputs = []; end

            % Set invariant properties
            this.Version    = 1.0;

            % Set public properties
            this.Configuration = config;
            this.InitialState  = states;
            this.Outputs       = outputs;

        end  % simoptions

    end  % constructor block

    methods
        function set.Configuration(obj,value)
            % DataType = 'handle'
            %validateattributes(value,{'handle'}, {'scalar'},'','Configuration')
            obj.Configuration = value;
        end

        function set.InitialState(obj,value)
            % DataType = 'handle vector'
            %validateattributes(value,{'handle'}, {'vector'},'','InitialState')
            obj.InitialState = LocalSetInitialState(obj,value);
        end

        function set.Outputs(obj,value)
            % DataType = 'handle vector'
            %validateattributes(value,{'handle'}, {'vector'},'','Outputs')
            obj.Outputs = LocalSetOutputs(obj,value);
        end

        function set.Description(obj,value)
            % DataType = 'ustring'
            % no cell string checks yet'
            obj.Description = value;
        end

        function set.Version(obj,value)
            % DataType = 'double'
            validateattributes(value,{'numeric'}, {'scalar'},'','Version')
            value = double(value); %  convert to double
            obj.Version = value;
        end

    end   % set and get functions
end  % classdef

function value = LocalSetOutputs(this, value) %#ok<INUSL>
cls = 'modelpack.PortID';
isValid = isa(value, cls);

if ~isempty(value) && ~isValid
    error(message('SLControllib:general:VectorClassMismatch', 'Outputs', cls ));
end
end  % LocalSetOutputs


function value = LocalSetInitialState(this, value) %#ok<INUSL>
cls = 'modelpack.StateValue';
isValid = isa(value, cls);

if ~isempty(value) && ~isValid
    error(message('SLControllib:general:VectorClassMismatch', 'InitialStates', cls ));
end
end  % LocalSetInitialState

% LocalWords:  INITIALSTATE
