# ============================================================
# RELIGIOUS & CULTURAL STRATEGY TRIGGERS
# ============================================================

# Holy Site Control
qyv_ai_should_control_holy_sites = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        any_owned_province = {
            is_holy_site = yes
            faith = root.faith
        }
        any_holy_site = {
            faith = root.faith
            controller = { NOT = { is_ruler = root } }
        }
    }
}

qyv_ai_should_create_head_of_faith = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        faith = { can_create_head_of_faith = yes }
        any_owned_province = {
            is_holy_site = yes
            faith = root.faith
            controller = { is_ruler = root }
        }
        controlled_holy_sites >= 3
    }
}

# Faith Reform
qyv_ai_should_reform_faith = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        faith = { can_reform = yes }
        piety >= 1500
        learning >= 12
        NOT = { has_faith = { is_reformed = yes } }
    }
}

qyv_ai_should_choose_tenets = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        faith = { is_reformed = yes }
        faith = { can_reform = no }
        # AI should pick tenets strategically
    }
}

# Holy War Strategy
qyv_ai_should_launch_holy_war = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        is_independent_ruler = yes
        NOT = { is_at_war = yes }
        piety >= 500
        any_neighbor_independent_ruler = {
            limit = {
                faith != root.faith
                military_strength < root.military_strength * 1.3
                NOT = { has_truce_with = root }
                any_owned_province = { is_holy_site = yes faith = root.faith }
            }
            save_scope_as = holy_war_target
        }
    }
}

qyv_ai_should_launch_great_holy_war = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        is_independent_ruler = yes
        NOT = { is_at_war = yes }
        piety >= 2000
        any_holy_site = {
            faith = root.faith
            controller = { NOT = { is_ruler = root } }
        }
    }
}

# Conversion Strategy
qyv_ai_should_convert_population = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        stewardship >= 14
        any_owned_province = {
            faith != root.faith
            culture != root.culture
            development >= 10
        }
    }
}

qyv_ai_should_use_learning_scenario = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        learning >= 14
        any_owned_province = {
            faith != root.faith
            development >= 10
        }
    }
}

qyv_ai_should_use_theologian = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        any_courtier = {
            is_court_chaplain = yes
            learning >= 16
        }
        any_owned_province = {
            faith != root.faith
        }
    }
}

# Culture Conversion
qyv_ai_should_convert_culture = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        prestige >= 1000
        any_owned_province = {
            culture != root.culture
            development >= 20
        }
    }
}

qyv_ai_should_promote_culture = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        stewardship >= 14
        any_owned_province = {
            culture = root.culture
            development < 15
        }
    }
}

qyv_ai_should_create_hybrid_culture = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        prestige >= 2000
        any_owned_province = {
            culture != root.culture
            development >= 15
        }
        NOT = { has_culture = { is_hybrid = yes } }
    }
}

qyv_ai_should_promote_culture_hybridization = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        any_owned_province = {
            culture != root.culture
            culture != { is_hybrid = yes }
            development >= 10
        }
    }
}

# Cultural Head of Faith
qyv_ai_should_become_cultural_head = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        culture = { can_have_cultural_head = yes }
        NOT = { culture = { has_cultural_head = yes } }
        prestige >= 2000
        any_owned_province = { culture = root.culture }
    }
}

# Pilgrimages
qyv_ai_should_go_on_pilgrimage = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        piety >= 300
        NOT = { has_character_flag = on_pilgrimage }
        any_holy_site = {
            faith = root.faith
            controller = { is_ruler = root }
        }
    }
}

# Religious Head Interaction
qyv_ai_should_request_claim = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        any_faith = {
            head_of_faith = { exists = yes }
            head_of_faith = { NOT = { is_ruler = root } }
            has_doctrine = religious_head
        }
        any_neighbor_independent_ruler = {
            limit = {
                faith = root.faith
                de_jure_liege = root
            }
        }
    }
}

qyv_ai_should_request_gold = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        gold < 200
        any_faith = {
            head_of_faith = { exists = yes }
            head_of_faith = { NOT = { is_ruler = root } }
            has_doctrine = religious_head
        }
        piety >= 500
    }
}

# Religious Head Decisions
qyv_ai_should_endorse_ruler = {
    trigger = {
        is_ai = yes
        is_faith_head = yes
        any_character = {
            is_ruler = yes
            faith = root.faith
            opinion_of_self >= 50
            NOT = { has_character_flag = endorsed_by_faith }
        }
    }
}

qyv_ai_should_excommunicate = {
    trigger = {
        is_ai = yes
        is_faith_head = yes
        any_character = {
            is_ruler = yes
            faith = root.faith
            OR = {
                is_rival_of = root
                has_trait = excommunicated
                has_attacked_faith = yes
            }
        }
    }
}

# Cultural Head Decisions
qyv_ai_should_use_cultural_head = {
    trigger = {
        is_ai = yes
        is_cultural_head = yes
        any_character = {
            is_ruler = yes
            culture = root.culture
            opinion_of_self >= 50
        }
    }
}

# Faith Doctrines Strategy
qyv_ai_should_choose_tenet_communion = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        faith = { can_reform = yes }
        NOT = { faith = { has_tenet = communion } }
        realm_size >= 20
    }
}

qyv_ai_should_choose_tenet_lay_clergy = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        faith = { can_reform = yes }
        NOT = { faith = { has_tenet = lay_clergy } }
        realm_size >= 15
    }
}

qyv_ai_should_choose_tenet_religious_head = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        faith = { can_reform = yes }
        NOT = { faith = { has_tenet = religious_head } }
        realm_size >= 30
    }
}

qyv_ai_should_choose_doctrine_gender_equality = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        faith = { can_reform = yes }
        NOT = { faith = { has_doctrine = gender_equality } }
        culture = { has_tradition = equal_inheritance }
    }
}

qyv_ai_should_choose_doctrine_female_temple = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        faith = { can_reform = yes }
        NOT = { faith = { has_doctrine = female_temple } }
        culture = { has_tradition = equal_inheritance }
    }
}