classdef stopSignHandler < handle
    properties
        scene
        stop_duration_rule
    end
    
    methods
        function obj = stopSignHandler(scene, stop_duration_rule)
            obj.scene = scene;
            obj.stop_duration_rule = stop_duration_rule;
        end
        function [propositions, ap_names] = traj2Propositions(obj, ts, xs, ~)
            propositions = zeros(size(xs,1),2);
            ap_names = ['s', 'a'];
            stop_sign_init_time = inf;
            is_a = false;
            for i = 1:size(xs,1)
                is_s = obj.scene.isCarFrontInStopRegion(xs(i,:));
                
                if is_s
                    % in stop region
                    if stop_sign_init_time == inf 
                        % first time in stop region
                        stop_sign_init_time = ts(i);
                        is_a = false;
                    elseif ts(i) - stop_sign_init_time > obj.stop_duration_rule
                        % been in stop region long enough to leave
                        is_a = true;
                    end
                else
                    stop_sign_init_time = inf;
                    is_a = false;
                end
                
                
                % if not in stop region and acceptable to go, no longer
                % need is_a = true. 
                % FIXME: Does this need to be set after setting 
                % propositions(i,:)?
%                 if ~is_s && is_a
%                     is_a = false;
%                     stop_sign_init_time = inf;
%                 end
                
                propositions(i,:) = [is_s, is_a];
            end
        end
    end
    
end