def METHOD_NAME(
    alert_rule: AlertRule,
    selected_incident: Optional[Incident] = None,
    new_status: Optional[IncidentStatus] = None,
    metric_value: Optional[str] = None,
):
    latest_incident = None
    if selected_incident is None:
        try:
            # Use .get() instead of .first() to avoid sorting table by id
            latest_incident = Incident.objects.filter(
                id__in=Incident.objects.filter(alert_rule=alert_rule)
                .values("alert_rule_id")
                .annotate(incident_id=Max("id"))
                .values("incident_id")
            ).get()
        except Incident.DoesNotExist:
            latest_incident = None
    if new_status:
        status = INCIDENT_STATUS[new_status]
    elif selected_incident:
        status = INCIDENT_STATUS[IncidentStatus(selected_incident.status)]
    elif latest_incident:
        status = INCIDENT_STATUS[IncidentStatus(latest_incident.status)]
    else:
        status = INCIDENT_STATUS[IncidentStatus.CLOSED]
    query = None
    if selected_incident:
        query = parse.urlencode({"alert": str(selected_incident.identifier)})
    title = f"{status}: {alert_rule.name}"
    title_link = alert_rule.organization.absolute_url(
        reverse(
            "sentry-metric-alert-details",
            kwargs={
                "organization_slug": alert_rule.organization.slug,
                "alert_rule_id": alert_rule.id,
            },
        ),
        query=query,
    )
    if metric_value is None:
        if (
            selected_incident is None
            and latest_incident
            and latest_incident.status != IncidentStatus.CLOSED
        ):
            # Without a selected incident, use latest incident if it is not resolved
            incident_info = latest_incident
        else:
            incident_info = selected_incident
        if incident_info:
            metric_value = get_metric_count_from_incident(incident_info)
    text = ""
    if metric_value is not None and status != INCIDENT_STATUS[IncidentStatus.CLOSED]:
        text = get_incident_status_text(alert_rule, metric_value)
    date_started = None
    if selected_incident:
        date_started = selected_incident.date_started
    last_triggered_date = None
    if latest_incident:
        last_triggered_date = latest_incident.date_started
    return {
        "title": title,
        "text": text,
        "logo_url": LOGO_URL,
        "status": status,
        "date_started": date_started,
        "last_triggered_date": last_triggered_date,
        "title_link": title_link,
    }