# By: Riasat Ullah
# This file contains all constants and functions related to the Prometheus integration.

from utils import constants

# Prometheus variables
var_alerts = 'alerts'
var_annotations = 'annotations'
var_alert_name = 'alertname'
var_description = 'description'
var_fingerprint = 'fingerprint'
var_generator_url = 'generatorURL'
var_labels = 'labels'
var_receiver = 'receiver'
var_severity = 'severity'
var_summary = 'summary'
var_status = 'status'

# Prometheus state values
firing_state = 'firing'
resolved_state = 'resolved'

# Internal TaskCall values
general_alert_name = 'Prometheus Alert'

# Prometheus severity mapped to TaskCall
severity_map = {
    'critical': constants.critical_urgency,
    'warning': constants.high_urgency,
    'error': constants.medium_urgency,
    'info': constants.low_urgency
}


def has_any_resolved_alert(all_alerts):
    '''
    Prometheus can send multiple alerts together. If any of the alerts is resolved, then it should be resolved.
    :param all_alerts: (list) of alerts
    :return: (boolean) True if any of the alerts is resolved; False otherwise
    '''
    for alert in all_alerts:
        if alert[var_status] == resolved_state:
            return True
    return False
