#!/bin/bash
# Copyright (c) 2025 - 2025, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
result=$(sqlite3 --json output/macaron.db "SELECT detect_malicious_metadata_check.detail_information
    FROM detect_malicious_metadata_check JOIN check_facts on detect_malicious_metadata_check.id = check_facts.id
    JOIN check_result on check_facts.check_result_id = check_result.id JOIN component
    ON component.id = check_result.component_id WHERE check_result.check_id = 'mcn_detect_malicious_metadata_1'
    AND component.name = 'smooth-operator'" | jq -r ".[0].detail_information | fromjson | .invalid_emails | length > 0")
if [[ "$result" == "false" ]]; then
    echo "ERROR: the invalid_emails report for smooth-operator is empty" >&2
    exit 1
fi

result=$(sqlite3 --json output/macaron.db "SELECT detect_malicious_metadata_check.detail_information
    FROM detect_malicious_metadata_check JOIN check_facts on detect_malicious_metadata_check.id = check_facts.id
    JOIN check_result on check_facts.check_result_id = check_result.id JOIN component
    ON component.id = check_result.component_id WHERE check_result.check_id = 'mcn_detect_malicious_metadata_1'
    AND component.name = 'email-validator'" | jq -r ".[0].detail_information | fromjson | .valid_emails | length > 0")
if [[ "$result" == "false" ]]; then
    echo "ERROR: the valid_emails report for email-validator is empty" >&2
    exit 2
fi
exit 0
