 
USE demo;

DROP PROCEDURE IF EXISTS demo.p_dog_get_many_assessment_response;

DELIMITER //
CREATE PROCEDURE demo.p_dog_get_many_assessment_response (
	  IN a_id_user INT
    , IN a_get_all_assessment_response BIT
	, IN a_get_inactive_assessment_response BIT
	, IN a_ids_assessment_response TEXT
	, IN a_notes_assessment_response TEXT
    , IN a_min_value_measured_assessment_response INT
    , IN a_max_value_measured_assessment_response INT
    
    , IN a_get_all_ACM_link BIT
	, IN a_get_inactive_ACM_link BIT
	, IN a_ids_ACM_link TEXT
    , IN a_min_distance_from_handler_metres_ACM_link FLOAT
    , IN a_max_distance_from_handler_metres_ACM_link FLOAT
    , IN a_value_is_in_sight_of_handler_ACM_link INT
    , IN a_value_is_in_scent_range_of_handler_ACM_link INT
    , IN a_value_is_in_hearing_range_of_handler_ACM_link INT
    , IN a_value_is_on_lead_ACM_link INT
    , IN a_min_trial_count_ACM_link FLOAT
    , IN a_max_trial_count_ACM_link FLOAT
    , IN a_get_all_assessment BIT
	, IN a_get_inactive_assessment BIT
	, IN a_ids_assessment TEXT
    , IN a_notes_assessment TEXT
    , IN a_min_temperature_assessment DECIMAL(5, 2)
    , IN a_max_temperature_assessment DECIMAL(5, 2)
    , IN a_get_all_weather BIT
	, IN a_get_inactive_weather BIT
	, IN a_ids_weather TEXT
    , IN a_names_weather TEXT
    , IN a_get_all_lighting_level BIT
	, IN a_get_inactive_lighting_level BIT
	, IN a_ids_lighting_level TEXT
    , IN a_names_lighting_level TEXT
    , IN a_get_all_location BIT
	, IN a_get_inactive_location BIT
	, IN a_ids_location TEXT
    , IN a_names_location TEXT
    , IN a_get_all_user_handler BIT
    , IN a_get_inactive_user_handler BIT
	, IN a_ids_user_handler TEXT
    -- , IN a_auth0_ids_user_handler TEXT
    , IN a_names_user_handler TEXT
    , IN a_emails_user_handler TEXT
    , IN a_get_all_command_category BIT
	, IN a_get_inactive_command_category BIT
	, IN a_ids_command_category TEXT
    , IN a_names_command_category TEXT
    , IN a_get_all_command BIT
	, IN a_get_inactive_command BIT
	, IN a_ids_command TEXT
    , IN a_names_command TEXT
    , IN a_hand_signal_default_descriptions_command TEXT
    , IN a_notes_command TEXT
    , IN a_get_all_command_modality BIT
	, IN a_get_inactive_command_modality BIT
	, IN a_ids_command_modality TEXT
	, IN a_names_command_modality TEXT
    , IN a_get_all_bribe BIT
	, IN a_get_inactive_bribe BIT
	, IN a_ids_bribe TEXT
	, IN a_names_bribe TEXT

    , IN a_get_all_response_quality_metric BIT
	, IN a_get_inactive_response_quality_metric BIT
	, IN a_ids_response_quality_metric TEXT
    , IN a_names_response_quality_metric TEXT
    
    , IN a_get_all_obedience_level BIT
	, IN a_get_inactive_obedience_level BIT
	, IN a_ids_obedience_level TEXT
    , IN a_names_obedience_level TEXT

    , IN a_require_all_id_search_filters_met BIT
    , IN a_require_any_id_search_filters_met BIT
    , IN a_require_all_non_id_search_filters_met BIT
    , IN a_require_any_non_id_search_filters_met BIT
    , IN a_debug BIT
)
BEGIN
    DECLARE v_can_view BIT;
    DECLARE v_code_type_error_bad_data VARCHAR(100);
    DECLARE v_code_type_error_no_permission VARCHAR(100);
    DECLARE v_guid BINARY(36);
    DECLARE v_id_access_level_view INT;
    DECLARE v_id_minimum INT;
    DECLARE v_id_permission_dog_view INT;
    DECLARE v_id_type_error_bad_data INT;
    DECLARE v_id_type_error_no_permission INT;
    DECLARE v_time_start TIMESTAMP(6);
    
    DECLARE exit handler for SQLEXCEPTION
    BEGIN
        GET DIAGNOSTICS CONDITION 1
            @sqlstate = RETURNED_SQLSTATE
            , @errno = MYSQL_ERRNO
            , @text = MESSAGE_TEXT
		;
        
        ROLLBACK;
        
		CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error (
			  id_error INT NOT NULL PRIMARY KEY AUTO_INCREMENT
			, id_type INT
			, code VARCHAR(250) NOT NULL
			, msg TEXT NOT NULL
		);

        INSERT INTO tmp_Msg_Error (
			  id_type
            , code
            , msg
		)
        SELECT 
			  MET.id_type
            , @errno
            , @text
		FROM demo.CORE_Msg_Error_Type MET
        WHERE MET.code = 'MYSQL_ERROR'
		;
        
        SELECT 
            t_ERROR.id_error
            , t_ERROR.id_type
            , t_ERROR.code
            , ERROR_TYPE.name
            , ERROR_TYPE.description
            , ERROR_TYPE.is_breaking_error
            , ERROR_TYPE.background_colour
            , ERROR_TYPE.text_colour
            , t_ERROR.msg
        FROM tmp_Msg_Error t_ERROR
        INNER JOIN demo.CORE_Msg_Error_Type ERROR_TYPE ON t_ERROR.id_type = ERROR_TYPE.id_type
        ;
        
		DROP TABLE IF EXISTS tmp_Msg_Error;
    END;

    SET v_time_start := CURRENT_TIMESTAMP(6);
    SET v_guid := UUID();
    SET v_code_type_error_bad_data := 'BAD_DATA';
    SET v_code_type_error_no_permission := 'NO_PERMISSION';
    SET v_id_type_error_bad_data := (SELECT ERROR_TYPE.id_type FROM demo.CORE_Msg_Error_Type ERROR_TYPE WHERE ERROR_TYPE.code = v_code_type_error_bad_data LIMIT 1);
    SET v_id_type_error_no_permission := (SELECT ERROR_TYPE.id_type FROM demo.CORE_Msg_Error_Type ERROR_TYPE WHERE ERROR_TYPE.code = v_code_type_error_no_permission LIMIT 1);
    SET v_id_permission_dog_view := (SELECT PERMISSION.id_permission FROM demo.DOG_Permission PERMISSION WHERE PERMISSION.code = 'DOG_VIEW' LIMIT 1);
    SET v_id_access_level_view := (SELECT ACCESS_LEVEL.id_access_level FROM demo.DOG_Access_Level ACCESS_LEVEL WHERE ACCESS_LEVEL.code = 'VIEW' LIMIT 1);
    
    SET a_id_user := IFNULL(a_id_user, 0);
    /*
    Filters handled by Calc
    */
    SET a_debug := IFNULL(a_debug, 0);
    
    IF a_debug = 1 THEN
		SELECT 
			  a_id_user
              
            , a_get_all_assessment_response
            , a_get_inactive_assessment_response
            , a_ids_assessment_response
            , a_notes_assessment_response
            , a_min_value_measured_assessment_response
            , a_max_value_measured_assessment_response
            
            , a_get_all_ACM_link
            , a_get_inactive_ACM_link
            , a_ids_ACM_link
            , a_min_distance_from_handler_metres_ACM_link
            , a_max_distance_from_handler_metres_ACM_link
            , a_value_is_in_sight_of_handler_ACM_link
            , a_value_is_in_scent_range_of_handler_ACM_link
            , a_value_is_in_hearing_range_of_handler_ACM_link
            , a_value_is_on_lead_ACM_link
            , a_min_trial_count_ACM_link
            , a_max_trial_count_ACM_link
            , a_get_all_assessment
            , a_get_inactive_assessment
            , a_ids_assessment
            , a_notes_assessment
            , a_min_temperature_assessment
            , a_max_temperature_assessment
            , a_get_all_weather
            , a_get_inactive_weather
            , a_ids_weather
            , a_names_weather
            , a_get_all_lighting_level
            , a_get_inactive_lighting_level
            , a_ids_lighting_level
            , a_names_lighting_level
            , a_get_all_location
            , a_get_inactive_location
            , a_ids_location
            , a_names_location
            , a_get_all_user_handler
            , a_get_inactive_user_handler
            , a_ids_user_handler
            -- , a_auth0_ids_user_handler
            , a_names_user_handler
            , a_emails_user_handler
            , a_get_all_command_category
            , a_get_inactive_command_category
            , a_ids_command_category
            , a_names_command_category
            , a_get_all_command
            , a_get_inactive_command
            , a_ids_command
            , a_names_command
            , a_hand_signal_default_descriptions_command
            , a_notes_command
            , a_get_all_command_modality
            , a_get_inactive_command_modality
            , a_ids_command_modality
            , a_names_command_modality
            , a_get_all_bribe
            , a_get_inactive_bribe
            , a_ids_bribe
            , a_names_bribe

            , a_get_all_response_quality_metric
            , a_get_inactive_response_quality_metric
            , a_ids_response_quality_metric
            , a_names_response_quality_metric

            , a_get_all_obedience_level
            , a_get_inactive_obedience_level
            , a_ids_obedience_level
            , a_names_obedience_level

            , a_require_all_id_search_filters_met
            , a_require_any_id_search_filters_met
            , a_require_all_non_id_search_filters_met
            , a_require_any_non_id_search_filters_met
            , a_debug
		;

        SELECT
              v_id_type_error_bad_data
            , v_id_type_error_no_permission
            , v_guid
            , v_id_permission_dog_view
            , v_time_start
        ;
    END IF;

    DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error;
    DROP TEMPORARY TABLE IF EXISTS tmp_Assessment_Response;
    
    CREATE TEMPORARY TABLE tmp_Assessment_Response (
		  id_response INT NOT NULL
        , id_assessment_command_modality_link INT
        , id_response_quality_metric INT
        , id_obedience_level INT
        , value_measured DOUBLE
        , notes TEXT
        , active BIT

        , does_meet_id_filters BIT
        , does_meet_non_id_filters BIT
    );
    
	CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error (
          id_error INT NOT NULL PRIMARY KEY AUTO_INCREMENT
		, id_type INT
		, code VARCHAR(250) NOT NULL
        , msg TEXT NOT NULL
    );
    
    -- Permissions
    IF a_debug = 1 THEN
		SELECT 
			  v_guid
            , 0 -- get_all_user
            , 0 -- get_inactive_user
            , a_id_user -- ids_user
            , '' -- a_auth0_ids_user
            , '' -- a_names_user
            , '' -- a_emails_user
            , 1 -- a_require_all_id_search_filters_met
            , 1 -- a_require_any_id_search_filters_met
            , 0 -- a_require_all_non_id_search_filters_met
            , 0 -- a_require_any_non_id_search_filters_met
            , v_id_permission_dog_view -- ids_permission
            , v_id_access_level_view -- ids_access_level
            , 0 -- a_show_errors
			, 0 -- a_debug
        ;
    END IF;
    
	CALL demo.p_dog_calc_user(
          v_guid
        , 0 -- get_all_user
        , 0 -- get_inactive_user
        , a_id_user -- ids_user
        , '' -- a_auth0_ids_user
        , '' -- a_names_user
        , '' -- a_emails_user
        , 1 -- a_require_all_id_search_filters_met
        , 1 -- a_require_any_id_search_filters_met
        , 0 -- a_require_all_non_id_search_filters_met
        , 0 -- a_require_any_non_id_search_filters_met
        , v_id_permission_dog_view -- ids_permission
        , v_id_access_level_view -- ids_access_level
        , 0 -- a_show_errors
        , 0 -- a_debug
    );
	
    SELECT
          IFNULL(CALC_USER_T.has_access, 0)
    INTO
          v_can_view
    FROM demo.DOG_Calc_User_Temp CALC_USER_T
    WHERE CALC_USER_T.GUID = v_guid
    LIMIT 1
    ;
    
    IF a_debug = 1 THEN
        SELECT v_can_view;
        SELECT COUNT(*) AS Count_Errors FROM tmp_Msg_Error t_ERROR;
        SELECT * FROM tmp_Msg_Error t_ERROR;
    END IF;
    
    IF (v_can_view = 0) THEN
		DELETE t_ME
        FROM tmp_Msg_Error t_ME
        WHERE t_ME.id_type <> v_id_type_error_no_permission
        ;
		INSERT INTO tmp_Msg_Error (
			  id_type
			, code
            , msg
		)
		VALUES (
			  v_id_type_error_no_permission
            , v_code_type_error_no_permission
			, 'You do not have permission to view Assessment_Responses.'
		)
        ;
    END IF;
	
	CALL demo.p_dog_clear_calc_user(
		  v_guid
        , 0 -- a_debug
	);

    
    -- Call Assessment_Response Calc
    IF NOT EXISTS(SELECT * FROM tmp_Msg_Error t_ERROR INNER JOIN demo.CORE_Msg_Error_Type ERROR_TYPE ON t_ERROR.id_type = ERROR_TYPE.id_type WHERE ERROR_TYPE.is_breaking_error = 1 LIMIT 1) THEN
        IF a_debug = 1 THEN
            SELECT 
                  v_guid -- a_guid
                , a_id_user -- a_id_user
                    
                , a_get_all_assessment_response
                , a_get_inactive_assessment_response
                , a_ids_assessment_response
                , a_notes_assessment_response
                , a_min_value_measured_assessment_response
                , a_max_value_measured_assessment_response
                
                , a_get_all_ACM_link
                , a_get_inactive_ACM_link
                , a_ids_ACM_link
                , a_min_distance_from_handler_metres_ACM_link
                , a_max_distance_from_handler_metres_ACM_link
                , a_value_is_in_sight_of_handler_ACM_link
                , a_value_is_in_scent_range_of_handler_ACM_link
                , a_value_is_in_hearing_range_of_handler_ACM_link
                , a_value_is_on_lead_ACM_link
                , a_min_trial_count_ACM_link
                , a_max_trial_count_ACM_link
                , a_get_all_assessment
                , a_get_inactive_assessment
                , a_ids_assessment
                , a_notes_assessment
                , a_min_temperature_assessment
                , a_max_temperature_assessment
                , a_get_all_weather
                , a_get_inactive_weather
                , a_ids_weather
                , a_names_weather
                , a_get_all_lighting_level
                , a_get_inactive_lighting_level
                , a_ids_lighting_level
                , a_names_lighting_level
                , a_get_all_location
                , a_get_inactive_location
                , a_ids_location
                , a_names_location
                , a_get_all_user_handler
                , a_get_inactive_user_handler
                , a_ids_user_handler
                -- , a_auth0_ids_user_handler
                , a_names_user_handler
                , a_emails_user_handler
                , a_get_all_command_category
                , a_get_inactive_command_category
                , a_ids_command_category
                , a_names_command_category
                , a_get_all_command
                , a_get_inactive_command
                , a_ids_command
                , a_names_command
                , a_hand_signal_default_descriptions_command
                , a_notes_command
                , a_get_all_command_modality
                , a_get_inactive_command_modality
                , a_ids_command_modality
                , a_names_command_modality
                , a_get_all_bribe
                , a_get_inactive_bribe
                , a_ids_bribe
                , a_names_bribe

                , a_get_all_response_quality_metric
                , a_get_inactive_response_quality_metric
                , a_ids_response_quality_metric
                , a_names_response_quality_metric

                , a_get_all_obedience_level
                , a_get_inactive_obedience_level
                , a_ids_obedience_level
                , a_names_obedience_level
                
                , a_require_all_id_search_filters_met -- a_require_all_id_search_filters_met
                , a_require_any_id_search_filters_met -- a_require_any_id_search_filters_met
                , a_require_all_non_id_search_filters_met -- a_require_all_non_id_search_filters_met
                , a_require_any_non_id_search_filters_met -- a_require_any_non_id_search_filters_met
                , 0 -- a_show_errors
                , 0 -- a_debug
            ;
        END IF;
        
        CALL demo.p_dog_calc_assessment_response (
              v_guid -- a_guid
            , a_id_user -- a_id_user
            
            , a_get_all_assessment_response
            , a_get_inactive_assessment_response
            , a_ids_assessment_response
            , a_notes_assessment_response
            , a_min_value_measured_assessment_response
            , a_max_value_measured_assessment_response
            
            , a_get_all_ACM_link
            , a_get_inactive_ACM_link
            , a_ids_ACM_link
            , a_min_distance_from_handler_metres_ACM_link
            , a_max_distance_from_handler_metres_ACM_link
            , a_value_is_in_sight_of_handler_ACM_link
            , a_value_is_in_scent_range_of_handler_ACM_link
            , a_value_is_in_hearing_range_of_handler_ACM_link
            , a_value_is_on_lead_ACM_link
            , a_min_trial_count_ACM_link
            , a_max_trial_count_ACM_link
            , a_get_all_assessment
            , a_get_inactive_assessment
            , a_ids_assessment
            , a_notes_assessment
            , a_min_temperature_assessment
            , a_max_temperature_assessment
            , a_get_all_weather
            , a_get_inactive_weather
            , a_ids_weather
            , a_names_weather
            , a_get_all_lighting_level
            , a_get_inactive_lighting_level
            , a_ids_lighting_level
            , a_names_lighting_level
            , a_get_all_location
            , a_get_inactive_location
            , a_ids_location
            , a_names_location
            , a_get_all_user_handler
            , a_get_inactive_user_handler
            , a_ids_user_handler
            -- , a_auth0_ids_user_handler
            , a_names_user_handler
            , a_emails_user_handler
            , a_get_all_command_category
            , a_get_inactive_command_category
            , a_ids_command_category
            , a_names_command_category
            , a_get_all_command
            , a_get_inactive_command
            , a_ids_command
            , a_names_command
            , a_hand_signal_default_descriptions_command
            , a_notes_command
            , a_get_all_command_modality
            , a_get_inactive_command_modality
            , a_ids_command_modality
            , a_names_command_modality
            , a_get_all_bribe
            , a_get_inactive_bribe
            , a_ids_bribe
            , a_names_bribe

            , a_get_all_response_quality_metric
            , a_get_inactive_response_quality_metric
            , a_ids_response_quality_metric
            , a_names_response_quality_metric

            , a_get_all_obedience_level
            , a_get_inactive_obedience_level
            , a_ids_obedience_level
            , a_names_obedience_level

            , a_require_all_id_search_filters_met -- a_require_all_id_search_filters_met
            , a_require_any_id_search_filters_met -- a_require_any_id_search_filters_met
            , a_require_all_non_id_search_filters_met -- a_require_all_non_id_search_filters_met
            , a_require_any_non_id_search_filters_met -- a_require_any_non_id_search_filters_met
            , 0 -- a_show_errors
            , 0 -- a_debug
        );
        
        IF a_debug = 1 THEN
            SELECT COUNT(*) FROM demo.DOG_Assessment_Response_Temp;
            SELECT * FROM demo.DOG_Assessment_Response_Temp;
        END IF;
        
        INSERT INTO tmp_Assessment_Response (
              id_response
            , id_assessment_command_modality_link
            , id_response_quality_metric
            , id_obedience_level
            , value_measured
            , notes
            , active

            , does_meet_id_filters
            , does_meet_non_id_filters
        )
        SELECT
              ASSESSMENT_RESPONSE_T.id_response
            , ASSESSMENT_RESPONSE_T.id_assessment_command_modality_link
            , ASSESSMENT_RESPONSE_T.id_response_quality_metric
            , ASSESSMENT_RESPONSE_T.id_obedience_level
            , ASSESSMENT_RESPONSE_T.value_measured
            , ASSESSMENT_RESPONSE_T.notes
            , ASSESSMENT_RESPONSE_T.active

            , ASSESSMENT_RESPONSE_T.does_meet_id_filters
            , ASSESSMENT_RESPONSE_T.does_meet_non_id_filters
        FROM demo.DOG_Assessment_Response_Temp ASSESSMENT_RESPONSE_T
        WHERE ASSESSMENT_RESPONSE_T.GUID = v_guid
        ;
        
        IF a_debug = 1 THEN
            SELECT COUNT(*) FROM tmp_Assessment_Response;
            SELECT * FROM tmp_Assessment_Response;
        END IF;
    END IF;
    
    -- Filter outputs
    IF EXISTS(SELECT * FROM tmp_Msg_Error t_ERROR INNER JOIN demo.CORE_Msg_Error_Type ERROR_TYPE ON t_ERROR.id_type = ERROR_TYPE.id_type WHERE ERROR_TYPE.is_breaking_error = 1 LIMIT 1) THEN
        IF a_debug = 1 THEN
            SELECT * FROM tmp_Assessment_Response;
        END IF;

        DELETE FROM tmp_Assessment_Response;
    END IF;


    -- Outputs
    -- Assessment_Responses
    SELECT 
          t_ASSESSMENT_RESPONSE.id_response
        , t_ASSESSMENT_RESPONSE.id_assessment_command_modality_link
        , t_ASSESSMENT_RESPONSE.id_response_quality_metric
        , RESPONSE_QUALITY_METRIC.name AS name_response_quality_metric
        , UNIT_MEASUREMENT.symbol AS symbol_unit_measurement_response_quality_metric
        , t_ASSESSMENT_RESPONSE.id_obedience_level
        , OBEDIENCE_LEVEL.name AS name_obedience_level
        , t_ASSESSMENT_RESPONSE.value_measured
        , t_ASSESSMENT_RESPONSE.notes
        , t_ASSESSMENT_RESPONSE.active

        , t_ASSESSMENT_RESPONSE.does_meet_id_filters
        , t_ASSESSMENT_RESPONSE.does_meet_non_id_filters
    FROM tmp_Assessment_Response t_ASSESSMENT_RESPONSE
    LEFT JOIN demo.DOG_Assessment_Response ASSESSMENT_RESPONSE ON t_ASSESSMENT_RESPONSE.id_response = ASSESSMENT_RESPONSE.id_response
    LEFT JOIN demo.DOG_Obedience_Level OBEDIENCE_LEVEL ON t_ASSESSMENT_RESPONSE.id_obedience_level = OBEDIENCE_LEVEL.id_obedience_level
    LEFT JOIN demo.DOG_Response_Quality_Metric RESPONSE_QUALITY_METRIC ON t_ASSESSMENT_RESPONSE.id_response_quality_metric = RESPONSE_QUALITY_METRIC.id_metric
    LEFT JOIN demo.DOG_Unit_Measurement UNIT_MEASUREMENT ON RESPONSE_QUALITY_METRIC.id_unit_measurement = UNIT_MEASUREMENT.id_unit_measurement
    ORDER BY ASSESSMENT_RESPONSE.created_on DESC
    LIMIT 1000
    ;

    -- Errors
    SELECT 
          t_ERROR.id_error
		, t_ERROR.id_type
        , t_ERROR.code
        , ERROR_TYPE.name
        , ERROR_TYPE.description
        , ERROR_TYPE.is_breaking_error
        , ERROR_TYPE.background_colour
        , ERROR_TYPE.text_colour
		, t_ERROR.msg
    FROM tmp_Msg_Error t_ERROR
	INNER JOIN demo.CORE_Msg_Error_Type ERROR_TYPE ON t_ERROR.id_type = ERROR_TYPE.id_type
	;
    
    IF a_debug = 1 AND v_can_view = 1 THEN
        SELECT * FROM tmp_Assessment_Response;
    END IF;
	
	CALL demo.p_dog_clear_calc_assessment_response(
		v_guid -- a_guid
        , 0 -- a_debug
	);
    
    DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error;
    DROP TEMPORARY TABLE IF EXISTS tmp_Assessment_Response;
    
    IF a_debug = 1 THEN
		CALL demo.p_core_debug_timing_reporting ( v_time_start );
    END IF;
END //
DELIMITER ;


/*

CALL demo.p_dog_get_many_assessment_response (
	  1 -- 'auth0|6582b95c895d09a70ba10fef',	-- a_id_user
      
    , 1                                     	-- a_get_all_assessment_response
	, 0                                     	-- a_get_inactive_assessment_response
	, ''                                    	-- a_ids_assessment_response
    , ''                                        -- a_notes_assessment_response
	, NULL                                     	-- a_min_value_measured_assessment_response
	, NULL                                     	-- a_max_value_measured_assessment_response

    , 1                                     	-- a_get_all_ACM_link
	, 0                                     	-- a_get_inactive_ACM_link
	, ''                                    	-- a_ids_ACM_link
    , NULL                                        -- a_min_distance_from_handler_metres_ACM_link
    , NULL                                        -- a_max_distance_from_handler_metres_ACM_link
    , NULL                                        -- a_value_is_in_sight_of_handler_ACM_link
    , NULL                                        -- a_value_is_in_scent_range_of_handler_ACM_link
    , NULL                                        -- a_value_is_in_hearing_range_of_handler_ACM_link
    , NULL                                        -- a_value_is_on_lead_ACM_link
    , NULL                                        -- a_min_trial_count_ACM_link
    , NULL                                        -- a_max_trial_count_ACM_link
    , 1                                     	-- a_get_all_assessment
	, 0                                     	-- a_get_inactive_assessment
	, ''                                    	-- a_ids_assessment
    , ''                                        -- a_notes_assessment
	, NULL                                     	-- a_min_temperature_assessment
	, NULL                                     	-- a_max_temperature_assessment
    , 1                                     	-- a_get_all_weather
	, 0                                     	-- a_get_inactive_weather
	, ''                                    	-- a_ids_weather
    , ''                                        -- a_names_weather
    , 1                                     	-- a_get_all_lighting_level
	, 0                                     	-- a_get_inactive_lighting_level
	, ''                                    	-- a_ids_lighting_level
    , ''                                        -- a_names_lighting_level
    , 1                                     	-- a_get_all_location
	, 0                                     	-- a_get_inactive_location
	, ''                                    	-- a_ids_location
    , ''                                        -- a_names_location
    , 1                                     	-- a_get_all_user_handler
	, 0                                     	-- a_get_inactive_user_handler
	, ''                                    	-- a_ids_user_handler
    -- , IN a_auth0_ids_user_handler TEXT
    , ''                                        -- a_names_user_handler
    , ''                                        -- a_emails_user_handler
    , 1                                     	-- a_get_all_command_category
	, 0                                     	-- a_get_inactive_command_category
	, ''                                    	-- a_ids_command_category
    , ''                                        -- a_names_command_category
    , 1                                     	-- a_get_all_command
	, 0                                     	-- a_get_inactive_command
	, ''                                    	-- a_ids_command
    , ''                                        -- a_names_command
    , ''                                        -- a_hand_signal_default_descriptions_command
    , ''                                        -- a_notes_command
    , 1                                     	-- a_get_all_command_modality
	, 0                                     	-- a_get_inactive_command_modality
	, ''                                    	-- a_ids_command_modality
    , ''                                        -- a_names_command_modality
    , 1                                     	-- a_get_all_bribe
	, 0                                     	-- a_get_inactive_bribe
	, ''                                    	-- a_ids_bribe
    , ''                                        -- a_names_bribe

    , 1                                     	-- a_get_all_response_quality_metric
	, 0                                     	-- a_get_inactive_response_quality_metric
	, ''                                    	-- a_ids_response_quality_metric
    , ''                                        -- a_names_response_quality_metric

    , 1                                     	-- a_get_all_obedience_level
	, 0                                     	-- a_get_inactive_obedience_level
	, ''                                    	-- a_ids_obedience_level
    , ''                                        -- a_names_obedience_level


    , 1                                         -- a_require_all_id_search_filters_met
    , 1                                         -- a_require_any_id_search_filters_met
    , 0                                         -- a_require_all_non_id_search_filters_met
    , 1                                         -- a_require_any_non_id_search_filters_met
    , 1                                     	-- a_debug
);

*/