% SLCOVERAGE.FILTERRULE Coverage filter rule class
%   Associates a filter rule selector with rationale and filter mode
%   fr = slcoverage.FilterRule(selector, rationale, mode)
%       selector:  slcoverage.Selector object
%       rationale: text
%       mode:      slcoverage.FilterMode.Exclude or 
%                  slcoverage.FilterMode.Justify (default)
%
% See also: SLCOVERAGE.BLOCKSELECTOR, SLCOVERAGE.METRICSELECTOR, 
%           SLCOVERAGE.SFCNSELECTOR, SLCOVERAGE.FILTERMODE 

% Copyright 2017 The MathWorks, Inc.

classdef FilterRule < handle
properties 
    %Selector - associated selector object
    %   See also SLCOVERAGE.SELECTOR
    Selector = '' 
    %Mode - filtering mode
    %   See also SLCOVERAGE.FILTERMODE
    Mode = slcoverage.FilterMode.Justify
    %Rationale - associated rationale
    Rationale = ''
end
methods
    function this = FilterRule(selector, rationale, varargin)
        narginchk(2, 3);
        [status, msgId] = SlCov.CoverageAPI.checkCvLicense;
        if status == 0
            error(message(msgId));
        end        
        mode = this.Mode;
        if nargin == 3
            mode = varargin{1};
        end 
        p = inputParser;
        selectorValidationFcn = @(x)validateattributes(x, {'slcoverage.Selector'}, {'scalar'}, 'FilterRule', 'selector', 1);
        p.addRequired('Selector', selectorValidationFcn);
        if ~isempty(rationale)
            rationaleValidationFcn = @(x)validateattributes(x, {'char'}, {'vector'}, 'FilterRule', 'rationale', 2);
        else
            rationaleValidationFcn = @(x)true;
        end
        p.addRequired('Rationale', rationaleValidationFcn);
        if isa(selector, 'slcoverage.MetricSelector')
            modeValidationFcn = @(x)validateattributes(x, {'slcoverage.FilterMode'},{'scalar', '>=', slcoverage.FilterMode.Justify}, 'FilterRule', 'mode', 3);
        else
            modeValidationFcn = @(x)validateattributes(x, {'slcoverage.FilterMode'}, {'scalar'}, 'FilterRule', 'mode', 3);
        end
        p.addRequired('Mode', modeValidationFcn);
        parse(p, selector, convertStringsToChars(rationale), mode);
        this.Selector = p.Results.Selector;
        this.Rationale = p.Results.Rationale;
        this.Mode = p.Results.Mode;
    end
end
end
