namespace = qyv_ai_religion

# ============================================================
# YEARLY: HOLY SITE CONTROL & FAITH REFORM
# ============================================================

character_event = {
    id = qyv_rel.0100
    hidden = yes
    is_triggered_only = no

    trigger = {
        is_ai = yes
        is_ruler = yes
        is_independent_ruler = yes
    }

    mean_time_to_happen = { months = 12 }

    immediate = {
        # Seize holy sites
        if = { limit = { qyv_ai_should_control_holy_sites = root } qyv_ai_seize_holy_sites = yes }

        # Create head of faith if eligible
        if = { limit = { qyv_ai_should_create_head_of_faith = root } qyv_ai_create_head_of_faith = yes }

        # Reform faith if eligible
        if = { limit = { qyv_ai_should_reform_faith = root } qyv_ai_reform_faith = yes }

        # Choose tenets/doctrines
        if = { limit = { faith = { is_reformed = yes } faith = { can_reform = no } } qyv_ai_choose_tenets = yes }
    }

    option = { name = "OK" }
}

# ============================================================
# YEARLY: HOLY WAR STRATEGY
# ============================================================

character_event = {
    id = qyv_rel.0200
    hidden = yes
    is_triggered_only = no

    trigger = {
        is_ai = yes
        is_ruler = yes
        is_independent_ruler = yes
        NOT = { is_at_war = yes }
        piety >= 500
    }

    mean_time_to_happen = { months = 12 }

    immediate = {
        # Launch holy war for holy sites
        if = { limit = { qyv_ai_should_launch_holy_war = root } qyv_ai_launch_holy_war = yes }

        # Launch great holy war
        if = { limit = { qyv_ai_should_launch_great_holy_war = root } qyv_ai_launch_great_holy_war = yes }
    }

    option = { name = "OK" }
}

# ============================================================
# QUARTERLY: CONVERSION & CULTURE
# ============================================================

character_event = {
    id = qyv_rel.0300
    hidden = yes
    is_triggered_only = no

    trigger = {
        is_ai = yes
        is_ruler = yes
    }

    mean_time_to_happen = { months = 3 }

    immediate = {
        # Convert population
        if = { limit = { qyv_ai_should_convert_population = root } qyv_ai_convert_population = yes }

        # Use learning scenario
        if = { limit = { qyv_ai_should_use_learning_scenario = root } qyv_ai_use_learning_scenario = yes }

        # Use court chaplain
        if = { limit = { qyv_ai_should_use_theologian = root } qyv_ai_use_theologian = yes }

        # Culture conversion
        if = { limit = { qyv_ai_should_convert_culture = root } qyv_ai_convert_culture = yes }

        # Promote culture
        if = { limit = { qyv_rel_qyv_ai_promote_culture = root } qyv_ai_promote_culture = yes }

        # Hybrid culture
        if = { limit = { qyv_ai_should_create_hybrid_culture = root } qyv_ai_create_hybrid_culture = yes }

        # Promote hybridization
        if = { limit = { qyv_ai_should_promote_culture_hybridization = root } qyv_ai_promote_hybridization = yes }

        # Become cultural head
        if = { limit = { qyv_ai_should_become_cultural_head = root } qyv_ai_become_cultural_head = yes }
    }

    option = { name = "OK" }
}

# ============================================================
# QUARTERLY: RELIGIOUS HEAD INTERACTIONS
# ============================================================

character_event = {
    id = qyv_rel.0400
    hidden = yes
    is_triggered_only = no

    trigger = {
        is_ai = yes
        is_ruler = yes
    }

    mean_time_to_happen = { months = 3 }

    immediate = {
        # Request claims from faith head
        if = { limit = { qyv_ai_should_request_claim = root } qyv_ai_request_claim = yes }

        # Request gold from faith head
        if = { limit = { qyv_ai_should_request_gold = root } qyv_ai_request_gold = yes }

        # Go on pilgrimage
        if = { limit = { qyv_ai_should_go_on_pilgrimage = root } qyv_ai_go_on_pilgrimage = yes }
    }

    option = { name = "OK" }
}

# ============================================================
# FAITH HEAD DECISIONS (Monthly)
# ============================================================

character_event = {
    id = qyv_rel.0500
    hidden = yes
    is_triggered_only = no

    trigger = {
        is_ai = yes
        is_faith_head = yes
    }

    mean_time_to_happen = { months = 1 }

    immediate = {
        # Endorse rulers
        if = { limit = { qyv_ai_should_endorse_ruler = root } qyv_ai_endorse_ruler = yes }

        # Excommunicate enemies
        if = { limit = { qyv_ai_should_excommunicate = root } qyv_ai_excommunicate = yes }
    }

    option = { name = "OK" }
}

# ============================================================
# CULTURAL HEAD DECISIONS (Monthly)
# ============================================================

character_event = {
    id = qyv_rel.0600
    hidden = yes
    is_triggered_only = no

    trigger = {
        is_ai = yes
        is_cultural_head = yes
    }

    mean_time_to_happen = { months = 1 }

    immediate = {
        # Use cultural head authority
        if = { limit = { qyv_ai_should_use_cultural_head = root } qyv_ai_use_cultural_head = yes }
    }

    option = { name = "OK" }
}

# ============================================================
# FAITH REFORM & TENETS (When Available)
# ============================================================

character_event = {
    id = qyv_rel.0700
    hidden = yes
    is_triggered_only = no

    trigger = {
        is_ai = yes
        is_ruler = yes
        faith = { can_reform = yes }
        NOT = { faith = { is_reformed = yes } }
        piety >= 1500
        learning >= 12
    }

    mean_time_to_happen = { months = 6 }

    immediate = {
        # Reform faith
        qyv_ai_reform_faith = yes

        # Choose tenets and doctrines strategically
        qyv_ai_choose_tenets_and_doctrines = yes
    }

    option = { name = "OK" }
}

# ============================================================
# ON_ACTIONS
# ============================================================

on_actions = {
    on_yearly_pulse = { events = { qyv_rel.0100 qyv_rel.0200 } }
    on_quarterly_pulse = { events = { qyv_rel.0300 qyv_rel.0400 } }
}