# ============================================================
# INTRIGUE & SCHEME CHAINS EFFECTS
# ============================================================

# Spy Network Effects
qyv_ai_build_spy_network = {
    scope:spymaster = {
        start_scheme = { scheme = scheme_build_spy_network target = scope:spy_target }
    }
    root = { add_stress = 5 }
}

qyv_ai_assign_spymaster = {
    scope:new_spymaster = {
        add_to_council = { position = spymaster }
    }
}

qyv_ai_replace_spymaster = {
    any_council_position = {
        limit = { position = spymaster }
        holder = { remove_from_council = yes }
    }
    any_realm_courtier = {
        limit = {
            intrigue >= 14
            NOT = { is_on_council = yes }
            NOT = { is_rival_of = root }
        }
        add_to_council = { position = spymaster }
    }
}

# Scheme Chain Effects
qyv_ai_scheme_murder = {
    scope:murder_target = {
        start_scheme = { scheme = scheme_murder target = root }
    }
    root = { add_stress = 15 }
}

qyv_ai_scheme_abduct = {
    scope:abduct_target = {
        start_scheme = { scheme = scheme_abduct target = root }
    }
    root = { add_stress = 20 }
}

qyv_ai_scheme_hook = {
    scope:hook_target = {
        start_scheme = { scheme = scheme_fabricate_hook target = root }
    }
    root = { add_stress = 10 }
}

qyv_ai_scheme_claim = {
    scope:claim_target = {
        start_scheme = { scheme = scheme_fabricate_claim target = root }
    }
    root = { add_stress = 10 }
}

qyv_ai_scheme_antiking = {
    scope:claimant = {
        start_scheme = { scheme = scheme_fabricate_claim target = root.liege }
    }
    root = { add_stress = 15 }
}

# Secret Exploitation
qyv_ai_use_secrets = {
    scope:secret_holder = {
        expose_secret = { target = root }
    }
    root = { add_opinion = { target = scope:secret_holder modifier = blackmail years = 10 } }
}

qyv_ai_blackmail = {
    if = {
        limit = {
            scope:blackmail_target = { is_vassal_of = root }
        }
        scope:blackmail_target = {
            enforce_hook = {
                target = root
                demand_gold = 200
            }
        }
    }
    else = {
        scope:blackmail_target = {
            enforce_hook = {
                target = root
                demand_council_position = yes
            }
        }
    }
}

# Hook Usage
qyv_ai_use_hook_on_vassal = {
    if = {
        limit = {
            scope:powerful_vassal = { is_vassal_of = root }
        }
        scope:powerful_vassal = {
            enforce_hook = {
                target = root
                demand_council_position = yes
            }
        }
    }
}

qyv_int_qyv_ai_use_hook_for_gold = {
    scope:hooked_character = {
        enforce_hook = {
            target = root
            demand_gold = 300
        }
    }
}

qyv_ai_use_hook_for_alliance = {
    scope:hooked_character = {
        enforce_hook = {
            target = root
            demand_alliance = yes
        }
    }
}

qyv_ai_use_hook_for_marriage = {
    scope:hooked_character = {
        enforce_hook = {
            target = root
            demand_marriage = { spouse = root }
        }
    }
}

# Expose Secrets
qyv_ai_expose_secret = {
    scope:rival = {
        expose_secret = { target = root }
    }
}

# Scheme Chain Completion Effects (triggered via on_scheme_end)
qyv_ai_on_murder_success = {
    if = {
        limit = { scope:target = { is_heir = yes } }
        scope:target = {
            disinherit = yes
        }
    }
}

qyv_ai_on_hook_fabricated = {
    if = {
        limit = { scope:target = { is_vassal_of = root } }
        root = {
            enforce_hook = {
                target = scope:target
                demand_council_position = yes
            }
        }
    }
}

qyv_ai_on_claim_fabricated = {
    if = {
        limit = {
            scope:target = { has_claim_on = root }
            NOT = { is_at_war = yes }
            gold >= 500
        }
        declare_war = { target = scope:target cb = claim }
    }
}