def generate_recommendations(rules):

    recommendations = []

    for rule in rules:

        issue = rule["issue"]

        # -----------------------------------
        # Low CTR
        # -----------------------------------

        if issue == "Low CTR detected":

            recommendations.append({
                "priority": "HIGH",
                "action": "Refresh ad creatives",
                "reason": "CTR performance is critically low"
            })

            recommendations.append({
                "priority": "MEDIUM",
                "action": "Improve CTA messaging",
                "reason": "Weak engagement detected"
            })

        # -----------------------------------
        # High Spend Low Conversion
        # -----------------------------------

        elif issue == "High spend with low conversions":

            recommendations.append({
                "priority": "HIGH",
                "action": "Optimize audience targeting",
                "reason": "Campaign spending inefficient"
            })

            recommendations.append({
                "priority": "MEDIUM",
                "action": "Reduce low-performing inventory",
                "reason": "Poor ROI detected"
            })

        # -----------------------------------
        # Creative Fatigue
        # -----------------------------------

        elif issue == "Creative fatigue detected":

            recommendations.append({
                "priority": "HIGH",
                "action": "Rotate banner creatives",
                "reason": "Creative fatigue impacting CTR"
            })

            recommendations.append({
                "priority": "LOW",
                "action": "Upload new creative variations",
                "reason": "Improve engagement freshness"
            })

        # -----------------------------------
        # Low Delivery
        # -----------------------------------

        elif issue == "Low delivery volume":

            recommendations.append({
                "priority": "MEDIUM",
                "action": "Expand inventory targeting",
                "reason": "Campaign delivery volume too low"
            })

        # -----------------------------------
        # Poor Health
        # -----------------------------------

        elif issue == "Campaign health critical":

            recommendations.append({
                "priority": "HIGH",
                "action": "Immediate optimization required",
                "reason": "Campaign performance critically low"
            })

    return recommendations