﻿#designate_theocratic_heir
#filial_piety_request_child_gold
#increase_theocratic_heir_candidacy
#influence_clerical_candidacy_interaction
#support_clerical_candidacy_interaction
#harm_clerical_candidacy_interaction
#request_realm_priest_replacement_interaction
#sway_ruler_to_my_rite_interaction
#appoint_cardinal_interaction
#request_court_chaplain_cardinalate_interaction
#give_cardinal_order_interaction
#request_legitimacy_interaction
#strengthen_claim_interaction
#ecclesiastic_grant_claim_interaction
#buy_ecclesiastical_title_interaction
#create_new_ecclesiastical_title_interaction
#expand_ecclesiastical_title_interaction
#split_ecclesiastical_title_interaction
#merge_new_ecclesiastical_title_interaction
#petition_antipope_indulgences_interaction
#petition_antipope_gold_interaction
#grant_pope_blessing_interaction
#sell_claim_interaction
#request_white_peace_interaction
#request_victory_interaction
#request_ecclesiastical_treasury_interaction
#request_enforce_succession_interaction
#increase_papabile_score_interaction
#seek_communion_interaction
#pam_destroy_monastic_order_interaction

# Appoint Cardinal Interaction

designate_theocratic_heir_interaction = {
	icon = heir
	category = interaction_category_diplomacy
	interface_priority = 1000

	desc = designate_theocratic_heir_interaction_desc

	is_available = {
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			has_realm_law = clerical_appointment_law
			NOT = { has_realm_law = theocratic_elective_succession_law }
			government_has_flag = government_is_theocracy
		}
		NOT = { scope:recipient = scope:puppet_or_actor }
		scope:recipient = {
			OR = { # Relevant people only
				is_councillor_of = scope:puppet_or_actor
				is_courtier_of = scope:puppet_or_actor
				scope:puppet_or_actor.house ?= house
				is_close_or_extended_family_of = scope:puppet_or_actor
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			is_adult = yes
			custom_tooltip = {
				text = designate_theocratic_heir_interaction_dynasty_tt
				exists = dynasty
			}
		}
		scope:recipient = {
			is_adult = yes # Children are not valid for Theocratic succession
			custom_tooltip = {
				text = designate_theocratic_heir_interaction_older_tt
				# The adoption below compares birth dates, not whole years, so equal ages are not enough
				birth_date >= scope:puppet_or_actor.birth_date
			}
			custom_tooltip = {
				text = designate_theocratic_heir_interaction_unlanded_tt
				is_ruler = no
			}
			custom_tooltip = {
				text = designate_theocratic_heir_interaction_faith_tt
				scope:puppet_or_actor.faith ?= faith
			}
			custom_tooltip = {
				text = pam_interaction_clerical_gender_tt
				trigger_if = {
					limit = { exists = scope:puppet_or_actor }
					can_be_granted_theocratic_titles_by = { RULER = scope:puppet_or_actor }
				}
			}
		}
		custom_tooltip = {
			text = designate_theocratic_heir_interaction_already_heir_tt
			NOR = {
				scope:puppet_or_actor.designated_heir ?= scope:recipient
				scope:puppet_or_actor.player_heir ?= scope:recipient
			}
		}
		scope:puppet_or_actor = {
			is_valid_designated_heir = scope:recipient
		}
		trigger_if = {
			limit = { scope:puppet_or_actor != scope:actor }
			scope:puppet_or_actor = {
				dynasty ?= { dynasty_prestige >= pam_designate_theocratic_heir_renown_cost_value }
			}
		}
		trigger_if = {
			limit = { scope:puppet_or_actor != scope:actor }
			scope:puppet_or_actor = {
				prestige >= pam_designate_theocratic_heir_prestige_cost_value
			}
		}
		trigger_if = {
			limit = { scope:puppet_or_actor != scope:actor }
			scope:puppet_or_actor = {
				piety >= major_piety_value
			}
		}
	}

	on_auto_accept = {
		scope:recipient = {
			trigger_event = char_interaction.0121
		}
	}

	on_accept = {
		if = {
			limit = { scope:puppet_or_actor != scope:actor }
			scope:puppet_or_actor = {
				if = {
					limit = { pam_designate_theocratic_heir_renown_cost_value > 0 }
					dynasty ?= {
						add_dynasty_prestige = {
							value = {
								add = pam_designate_theocratic_heir_renown_cost_value
								multiply = -1
							}
						}
					}
				}
				if = {
					limit = { pam_designate_theocratic_heir_prestige_cost_value > 0 }
					add_prestige = {
						value = {
							add = pam_designate_theocratic_heir_prestige_cost_value
							max = prestige
							multiply = -1
						}
					}
				}
				add_piety = { value = { add = major_piety_value max = piety multiply = -1 } }
			}
		}
		scope:puppet_or_actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = designate_heir_interaction_notification

				left_icon = scope:puppet_or_actor
				right_icon = scope:recipient

				# The order of operations on this one matters
				hidden_effect = { # To not clout the toast even more
					if = {
						limit = {
							scope:recipient = {
								NOT = { is_courtier_of = scope:puppet_or_actor }
							}
						}
						add_courtier = scope:recipient
					}
				}

				if = { # set_designated_heir only accepts direct descendants, so everyone else is adopted in first
					limit = {
						scope:recipient = {
							NOT = { is_child_of = scope:puppet_or_actor }
						}
					}
					adopt_effect = {
						CHILD = scope:recipient
						ADOPTER = scope:puppet_or_actor
					}
				}

				primary_title = { # Enough to put them first
					change_appointment_investment = {
						target = scope:recipient
						investor = scope:puppet_or_actor
						value = {
							if = { # An appointment title without eligible candidates has no current heir to outbid
								limit = { exists = scope:puppet_or_actor.primary_title.current_heir }
								add = {
									value = "scope:puppet_or_actor.primary_title.current_heir.appointment_candidate_score(scope:puppet_or_actor.primary_title)"
									multiply = 1.1
								}
								subtract = "scope:recipient.appointment_candidate_score(scope:puppet_or_actor.primary_title)"
							}
							min = 4 # We do this to prevent cases when the default score of the candidate is already much higher than that the heir
						}
					}
				}

				set_designated_heir = scope:recipient
			}
		}
		notify_puppeteer_of_outcome_effect = {
			TYPE = event_toast_effect_neutral
			TITLE = designate_heir_interaction_notification_puppeteer
		}
	}

	auto_accept = yes

	cost = {
		renown = {
			value = pam_designate_theocratic_heir_renown_cost_value
			if = {
				limit = { scope:puppet_or_actor != scope:actor }
				multiply = 0
			}
		}
		prestige = {
			value = pam_designate_theocratic_heir_prestige_cost_value
			if = {
				limit = { scope:puppet_or_actor != scope:actor }
				multiply = 0
			}
		}
		piety = {
			value = {
				add = major_piety_value
			}
			if = {
				limit = { scope:puppet_or_actor != scope:actor }
				multiply = 0
			}
		}
	}

	ai_targets = {
		ai_recipients = family
		ai_recipients = courtiers
		ai_recipients = vassals
		max = 5
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 120
		duchy = 60
		kingdom = 60
		empire = 60
		hegemony = 60
	}

	ai_will_do = {
		base = 50

		modifier = { # Traits in common
			add = 25
			scope:puppet_or_actor = {
				number_of_personality_traits_in_common = {
					target = scope:recipient
					value = 1
				}
			}
		}

		modifier = { # Traits in common
			add = 25
			scope:puppet_or_actor = {
				number_of_personality_traits_in_common = {
					target = scope:recipient
					value = 2
				}
			}
		}

		modifier = { # Traits in common
			add = 25
			scope:puppet_or_actor = {
				number_of_personality_traits_in_common = {
					target = scope:recipient
					value = 3
				}
			}
		}

		modifier = { # I like them
			add = 25
			scope:puppet_or_actor = {
				opinion = {
					value >= medium_positive_opinion
					target = scope:recipient
				}
			}
		}

		modifier = { # Same rite
			factor = 2
			scope:puppet_or_actor.rite = scope:recipient.rite
		}

		modifier = {
			factor = 0
			scope:puppet_or_actor.designated_heir ?= { is_alive = yes }
		}

		modifier = {
			factor = 0
			scope:recipient = {
				OR = {
					any_heir_title = {
						exists = holder
						holder != scope:puppet_or_actor
					}
					employer ?= {
						is_ai = no
						this != scope:puppet_or_actor
					}
				}
			}
		}
	}
}

filial_piety_request_child_gold_interaction = {
	category = interaction_category_friendly
	icon = icon_gold
	interface_priority = 30
	common_interaction = yes
	ai_maybe = no
	popup_on_receive = yes
	use_diplomatic_range = yes

	desc = filial_piety_request_child_gold_interaction_desc
	notification_text = filial_piety_request_child_gold_notification

	cooldown_against_recipient = { years = 5 }

	is_shown = {
		scope:actor = {
			has_personal_tenet_flag = tenet_filial_piety_child_gold_request
			is_available_adult = yes
		}
		scope:recipient = {
			is_child_of = scope:actor
			is_available_adult = yes
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_available_adult = yes
			NOT = { is_at_war_with = scope:recipient }
		}
		scope:recipient = {
			is_available_adult = yes
			custom_tooltip = {
				text = filial_piety_request_child_gold_not_enough_gold
				gold > 20
			}
		}
	}

	auto_accept = yes

	on_accept = {
		save_scope_value_as = {
			name = requested_gold_value
			value = {
				value = scope:recipient.gold
				divide = 4
				multiply = {
					value = scope:recipient.ai_greed
					divide = -300
					add = 1
				}
				if = {
					limit = {
						scope:recipient = {
							has_any_best_good_relationship_with_character_trigger = {
								CHARACTER = scope:actor
							}
						}
					}
					multiply = 1.5
				}
				else_if = {
					limit = {
						scope:recipient = {
							has_any_moderate_good_relationship_with_character_trigger = {
								CHARACTER = scope:actor
							}
						}
					}
					multiply = 1.25
				}
				max = {
					scope:recipient.culture = {
						if = {
							limit = { has_cultural_era_or_later = culture_era_late_medieval }
							value = 250
						}
						else_if = {
							limit = { has_cultural_era_or_later = culture_era_high_medieval }
							value = 200
						}
						else_if = {
							limit = { has_cultural_era_or_later = culture_era_early_medieval }
							value = 150
						}
						else_if = {
							limit = { has_cultural_era_or_later = culture_era_tribal }
							value = 100
						}
						else = {
							value = 50
						}
					}
				}
				floor = yes
				min = 5
			}
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = filial_piety_request_child_gold_actor_toast
				left_icon = scope:actor
				right_icon = scope:recipient
				show_as_tooltip = {
					add_gold = scope:requested_gold_value
				}
			}
		}
		scope:recipient = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = filial_piety_request_child_gold_recipient_toast
				left_icon = scope:recipient
				right_icon = scope:actor
				pay_short_term_gold = {
					target = scope:actor
					gold = scope:requested_gold_value
				}
			}
		}
	}
}

increase_theocratic_heir_candidacy = {
	icon = icon_increase_theocratic_heir_candidacy
	category = interaction_category_diplomacy
	interface_priority = 800

	desc = increase_theocratic_heir_candidacy_desc

	target_type = title
	target_source = puppet_or_actor
	target_filter = domain_titles # TODO_PAM_VP Ecc. Titles filter

	is_shown = {
		scope:puppet_or_actor ?= { # You need to have a valid title no matter what
			any_held_title = {
				OR = {
					holder ?= { has_realm_law = clerical_appointment_law }
					has_title_law = clerical_appointment_law
				}
			}
		}
		has_pam_dlc_trigger = yes
		trigger_if = { # For Theocracies, boost your Heir/courtiers/house members
			limit = {
				scope:puppet_or_actor ?= {
					has_realm_law = clerical_appointment_law
					government_has_flag = government_is_theocracy
				}
			}
			OR = {
				scope:puppet_or_actor.player_heir ?= scope:secondary_recipient
				scope:secondary_recipient ?= {
					is_ruler = no
					is_available = yes
					faith ?= scope:puppet_or_actor.faith
					OR = {
						is_close_or_extended_family_of = scope:puppet_or_actor
						is_courtier_of = scope:puppet_or_actor
					}
					can_be_granted_theocratic_titles_by = { RULER = scope:puppet_or_actor }
				}
			}
		}
		trigger_else = { # For normal rulers, boost members of your house if you're the House Head
			scope:puppet_or_actor ?= {
				exists = house
				is_house_head = yes
				NOT = { government_has_flag = government_is_theocracy }
				faith ?= scope:secondary_recipient.faith
				house ?= scope:secondary_recipient.house
			}
			scope:secondary_recipient ?= {
				is_ruler = no
				is_available = yes
				trigger_if = {
					limit = { exists = scope:puppet_or_actor }
					can_be_granted_theocratic_titles_by = { RULER = scope:puppet_or_actor }
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			is_adult = yes # Children are not valid for Theocratic succession
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= pam_increase_theocratic_heir_candidacy_cost_value
			}
		}
	}

	custom_character_sort = { candidate_score }

	populate_recipient_list = {
		scope:puppet_or_actor = {
			house ?= {
				every_house_member = {
					limit = {
						top_liege != this
						faith = scope:puppet_or_actor.faith
						is_ruler = no
						can_be_granted_theocratic_titles_by = { RULER = scope:puppet_or_actor }
					}
					add_to_list = characters
				}
			}
			if = {
				limit = { government_has_flag = government_is_theocracy }
				designated_heir ?= {
					add_to_list = characters
				}
				every_courtier = {
					limit = {
						is_available = yes
						faith = scope:puppet_or_actor.faith
						can_be_granted_theocratic_titles_by = { RULER = scope:puppet_or_actor }
					}
					add_to_list = characters
				}
				every_close_or_extended_family_member = {
					limit = {
						is_available = yes
						faith = scope:puppet_or_actor.faith
						can_be_granted_theocratic_titles_by = { RULER = scope:puppet_or_actor }
					}
					add_to_list = characters
				}
			}
		}
	}

	can_be_picked_title = {
		scope:target = {
			# domain_titles offers baronies too, and appointment investment is county tier and up
			tier >= tier_county
			is_head_of_faith = no
			OR = {
				this = scope:puppet_or_actor.primary_title
				trigger_if = {
					limit = { exists = scope:secondary_recipient }
					is_clerical_appointment_valid_trigger = {
						TITLE = scope:target
						CANDIDATE = scope:secondary_recipient
						TOP_LIEGE = scope:puppet_or_actor
					}
				}
			}
		}
	}

	has_valid_target_showing_failures_only = {
		exists = scope:target
		exists = scope:recipient
		scope:target = {
			exists = holder
			OR = {
				has_title_law = clerical_appointment_law
				holder = { has_realm_law = clerical_appointment_law }
			}
		}
	}

	redirect = {
		scope:recipient = { save_scope_as = secondary_recipient }
		scope:puppet_or_actor = {
			if = {
				limit = {
					NOT = {
						faith = { has_doctrine_parameter = no_head_of_faith }
					}
				}
				faith.religious_head ?= { save_scope_as = recipient }
			}
		}
	}

	auto_accept = yes

	send_option = {
		flag = as_much_as_needed_candidacy_option
		localization = "as_much_as_needed_candidacy_option_desc"
		is_valid = {
			trigger_if = {
				limit = {
					exists = scope:target
					exists = scope:secondary_recipient
				}
				custom_tooltip = {
					text = already_first_in_line_candidacy_option_desc
					NOT = { scope:target.current_heir = scope:secondary_recipient }
				}
			}
		}
	}
	send_option = {
		flag = major_candidacy_option
		localization = "major_candidacy_option_desc"
	}
	send_option = {
		flag = medium_candidacy_option
		localization = "medium_candidacy_option_desc"
		starts_enabled = { always = yes }
	}

	localization_values = {
		AS_MUCH_AS_NEEDED_CANDIDACY_OPTION = scope:puppet_or_actor.clerical_appointment_score_max_tt_value
		MAJOR_CANDIDACY_OPTION = scope:puppet_or_actor.clerical_appointment_score_major_tt_value
		MEDIUM_CANDIDACY_OPTION = scope:puppet_or_actor.clerical_appointment_score_medium_tt_value
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				if = {
					limit = { pam_increase_theocratic_heir_candidacy_cost_value > 0 }
					add_piety = {
						value = {
							add = pam_increase_theocratic_heir_candidacy_cost_value
							max = piety
							multiply = -1
						}
					}
				}
			}
		}
		switch = {
			trigger = yes
			scope:as_much_as_needed_candidacy_option = {
				# Save the score value
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = clerical_appointment_score_max_value
						multiply = scope:puppet_or_actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:puppet_or_actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
			}
			scope:major_candidacy_option = {
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_major_value
						multiply = scope:puppet_or_actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:puppet_or_actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
			}
			scope:medium_candidacy_option = {
				# Save the score value
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_medium_value
						multiply = scope:puppet_or_actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:puppet_or_actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
			}
		}
		scope:puppet_or_actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = increase_theocratic_heir_candidacy_notification

				left_icon = scope:puppet_or_actor
				right_icon = scope:secondary_recipient

				scope:target = {
					change_appointment_investment = {
						target = scope:secondary_recipient
						investor = scope:puppet_or_actor
						value = scope:support_candidate_score
					}
				}
			}
		}
		if = {
			limit = {
				scope:is_puppet_action ?= yes
				scope:actor != scope:recipient
			}
			scope:actor = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = increase_theocratic_heir_candidacy_notification_puppeteer
					left_icon = scope:puppet_or_actor
					right_icon = scope:secondary_recipient
				}
			}
		}
		hidden_effect = {
			scope:secondary_recipient = {
				send_interface_message = {
					type = msg_candidacy_improved
					title = supported_candidacy_toast
					left_icon = scope:puppet_or_actor
					right_icon = scope:target
					show_as_tooltip = {
						scope:target = {
							change_appointment_investment = {
								target = scope:secondary_recipient
								investor = scope:puppet_or_actor
								value = scope:support_candidate_score
							}
						}
					}
				}
			}
		}
	}

	auto_accept = yes

	cost = {
		piety = {
			value = pam_increase_theocratic_heir_candidacy_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	ai_targets = {
		ai_recipients = family
		ai_recipients = scripted_relations
		ai_recipients = courtiers
		max = 20
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 240
		duchy = 120
		kingdom = 120
		empire = 120
		hegemony = 120
	}

	ai_will_do = {
		base = 50

		modifier = { # Traits in common
			add = 25
			scope:puppet_or_actor = {
				number_of_personality_traits_in_common = {
					target = scope:secondary_recipient
					value = 1
				}
			}
		}

		modifier = { # Traits in common
			add = 25
			scope:puppet_or_actor = {
				number_of_personality_traits_in_common = {
					target = scope:secondary_recipient
					value = 2
				}
			}
		}

		modifier = { # Traits in common
			add = 25
			scope:puppet_or_actor = {
				number_of_personality_traits_in_common = {
					target = scope:secondary_recipient
					value = 3
				}
			}
		}

		modifier = { # I like this guy
			add = 25
			scope:puppet_or_actor = {
				opinion = {
					value >= medium_positive_opinion
					target = scope:secondary_recipient
				}
			}
		}

		modifier = { # This guy is my friend
			add = 25
			scope:puppet_or_actor = {
				has_relation_friend = scope:secondary_recipient
			}
		}

		modifier = { # Same rite
			factor = 2
			scope:puppet_or_actor.rite = scope:secondary_recipient.rite
		}
	}
}

# Players only, because the AI has no ai_targets and uses support_clerical_candidacy_interaction instead
influence_clerical_candidacy_interaction = {
	icon = support_candidacy
	category = interaction_category_religion
	common_interaction = yes
	interface_priority = 750

	desc = influence_clerical_candidacy_interaction_desc

	target_type = title
	target_source = actor
	# This is for clerical regions, not Head of Faith or Head of Rite titles
	# Those use influence_head_of_faith_candidacy_interaction
	target_filter = faith_clerical_regions

	custom_character_sort = { candidate_score }

	is_available = {
		has_pam_dlc_trigger = yes
		faith ?= { has_doctrine_parameter = has_clerical_regions }
	}

	is_shown = {
		scope:secondary_recipient ?= {
			this != faith.main_rite.head_of_rite
			faith ?= scope:actor.faith
			pam_holds_church_seat_trigger = no
			is_clerical_appointment_valid_base_trigger = {
				CANDIDATE = scope:secondary_recipient
				TOP_LIEGE = scope:actor
			}
			NOR = {
				scope:actor.religious_head_or_challenger ?= this
				scope:secondary_recipient.religious_head_or_challenger ?= this
			}
			OR = {
				is_clergy = yes
				influence_clerical_candidacy_any_valid_title_trigger = yes
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			is_adult = yes
		}
		trigger_if = {
			limit = {
				exists = scope:target
			}
			scope:secondary_recipient = {
				is_clerical_appointment_valid_trigger = {
					TITLE = scope:target
					CANDIDATE = scope:secondary_recipient
					TOP_LIEGE = scope:actor
				}
			}
		}
		pam_clerical_self_candidacy_restriction_trigger = yes
		trigger_if = {
			limit = {
				pam_clerical_candidacy_reach_limited_trigger = yes
			}
			custom_tooltip = {
				text = influence_clerical_candidacy_no_valid_title_in_realm_tt
				influence_clerical_candidacy_any_valid_title_trigger = yes
			}
		}
		trigger_else = {
			custom_tooltip = {
				text = influence_clerical_candidacy_no_valid_title_tt
				influence_clerical_candidacy_any_valid_title_trigger = yes
			}
		}
	}

	can_be_picked_title = {
		trigger_if = {
			limit = { exists = scope:secondary_recipient }
			custom_tooltip = {
				text = influence_clerical_candidacy_interaction_already_holds_title_tt
				scope:target = {
					holder != scope:secondary_recipient
				}
			}
		}
		pam_clerical_self_candidacy_restriction_trigger = yes
		influence_clerical_candidacy_reach_trigger = yes
	}

	has_valid_target_showing_failures_only = {
		exists = scope:target
		exists = scope:recipient
		scope:target = {
			OR = {
				has_title_law = clerical_appointment_law
				holder ?= { has_realm_law = clerical_appointment_law }
			}
		}
		influence_clerical_candidacy_reach_trigger = yes
	}

	redirect = {
		scope:recipient = { save_scope_as = secondary_recipient }
		scope:actor.faith.main_rite.head_of_rite ?= { save_scope_as = recipient }
	}

	can_send = {
		trigger_if = {
			limit = {
				OR = {
					scope:as_much_as_needed_candidacy_option ?= yes
					scope:major_candidacy_option ?= yes
					scope:medium_candidacy_option ?= yes
				}
			}
			scope:actor = {
				custom_tooltip = {
					text = support_candidacy_cap_reached_tt
					succession_appointment_score_invested = {
						title = scope:target
						candidate = scope:secondary_recipient
						value < scope:actor.appointment_investment_cap
					}
				}
			}
		}
	}

	auto_accept = yes

	send_option = {
		flag = as_much_as_needed_candidacy_option
		localization = as_much_as_needed_candidacy_option_desc
		is_valid = {
			trigger_if = {
				limit = {
					exists = scope:target
					exists = scope:secondary_recipient
				}
				custom_tooltip = {
					text = already_first_in_line_candidacy_option_desc
					NOT = { scope:target.current_heir = scope:secondary_recipient }
				}
			}
		}
	}
	send_option = {
		flag = major_candidacy_option
		localization = major_candidacy_option_desc
	}
	send_option = {
		flag = medium_candidacy_option
		localization = medium_candidacy_option_desc
		starts_enabled = { always = yes }
	}
	send_option = {
		flag = medium_candidacy_loss_option
		localization = medium_candidacy_loss_option_desc
	}
	send_option = {
		flag = major_candidacy_loss_option
		localization = major_candidacy_loss_option_desc
	}

	localization_values = {
		AS_MUCH_AS_NEEDED_CANDIDACY_OPTION = scope:actor.clerical_appointment_score_max_tt_value
		MAJOR_CANDIDACY_OPTION = scope:actor.clerical_appointment_score_major_tt_value
		MEDIUM_CANDIDACY_OPTION = scope:actor.clerical_appointment_score_medium_tt_value
		MEDIUM_CANDIDACY_LOSS_OPTION = scope:actor.appointment_score_medium_loss_tt_value
		MAJOR_CANDIDACY_LOSS_OPTION = scope:actor.appointment_score_major_loss_tt_value
	}

	cost = {
		piety = {
			value = {
				add = 0
				switch = {
					trigger = yes
					scope:as_much_as_needed_candidacy_option = {
						add = {
							value = pam_clerical_candidacy_outbid_piety_base_cost_value
						}
					}
					scope:major_candidacy_option = {
						add = { value = massive_piety_value }
					}
					scope:medium_candidacy_option = {
						add = { value = major_piety_value }
					}
					scope:medium_candidacy_loss_option = {
						add = { value = major_piety_value }
					}
					scope:major_candidacy_loss_option = {
						add = { value = massive_piety_value }
					}
				}
				multiply = scope:actor.pam_increase_theocratic_heir_candidacy_piety_cost_mult_value
			}
		}
	}

	on_accept = {
		switch = {
			trigger = yes
			scope:as_much_as_needed_candidacy_option = {
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = clerical_appointment_score_max_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = 15
				}
			}
			scope:major_candidacy_option = {
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_major_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = 10
				}
			}
			scope:medium_candidacy_option = {
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_medium_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = 5
				}
			}
			scope:medium_candidacy_loss_option = {
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_medium_loss_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = -10
				}
			}
			scope:major_candidacy_loss_option = {
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_major_loss_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = -20
				}
			}
		}

		if = {
			limit = {
				OR = {
					scope:as_much_as_needed_candidacy_option = yes
					scope:major_candidacy_option = yes
					scope:medium_candidacy_option = yes
				}
			}
			scope:secondary_recipient ?= {
				if = {
					limit = {
						this = scope:actor
						is_landless_adventurer = yes
						is_clergy = no
					}
					add_trait = cleric
				}
				if = {
					limit = { this != scope:actor }
					hidden_effect = {
						send_interface_message = {
							type = msg_candidacy_improved
							title = supported_candidacy_toast
							left_icon = scope:actor
							right_icon = scope:target
							show_as_tooltip = {
								scope:target = {
									change_appointment_investment = {
										target = scope:secondary_recipient
										investor = scope:actor
										value = scope:support_candidate_score
									}
								}
							}
						}
					}
					add_opinion = {
						modifier = supported_candidacy_opinion
						target = scope:actor
						opinion = scope:opinion_change_value
					}
				}
			}
		}
		else = {
			scope:secondary_recipient ?= {
				if = {
					limit = { this != scope:actor }
					hidden_effect = {
						send_interface_message = {
							type = msg_candidacy_harmed
							title = harmed_candidacy_toast
							left_icon = scope:actor
							right_icon = scope:target
							show_as_tooltip = {
								scope:target = {
									change_appointment_investment = {
										target = scope:secondary_recipient
										investor = scope:actor
										value = scope:support_candidate_score
									}
								}
							}
						}
					}
					add_opinion = {
						modifier = harmed_candidacy_opinion
						target = scope:actor
						opinion = scope:opinion_change_value
					}
				}
			}
		}

		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = influence_clerical_candidacy_interaction_notification
				left_icon = scope:actor
				right_icon = scope:secondary_recipient
				scope:target = {
					change_appointment_investment = {
						target = scope:secondary_recipient
						investor = scope:actor
						value = scope:support_candidate_score
					}
				}
			}
		}

		# Christian Situation Catalysts
		if = {
			limit = {
				scope:actor = {
					NOR = {
						government_has_flag = government_is_ecclesiastical
						this = faith.main_rite.head_of_rite
					}
				}
				situation:the_christian_church ?= {
					situation_top_has_catalyst = catalyst_secular_influenced_clerical_candidacy
				}
			}
			situation:the_christian_church = {
				trigger_situation_catalyst = catalyst_secular_influenced_clerical_candidacy
			}
		}
		if = {
			limit = {
				scope:actor ?= scope:secondary_recipient
				scope:actor = {
					government_has_flag = government_is_ecclesiastical
				}
				situation:the_christian_church ?= {
					situation_top_has_catalyst = catalyst_clergy_influenced_own_candidacy
				}
			}
			situation:the_christian_church = {
				trigger_situation_catalyst = catalyst_clergy_influenced_own_candidacy
			}
		}
	}
}

# PLAYER ONLY - Head of Faith and Head of Rite titles are not clerical regions, so they need their own picker
influence_head_of_faith_candidacy_interaction = {
	icon = support_candidacy
	category = interaction_category_religion
	interface_priority = 50

	desc = influence_head_of_faith_candidacy_interaction_desc

	target_type = title
	target_source = actor
	target_filter = religious_head_titles

	custom_character_sort = { candidate_score }

	is_available = {
		has_pam_dlc_trigger = yes
		# Mirrors the religious_head_titles filter, so a faith whose head titles are all filled by conclave or inheritance hides the interaction instead of opening an empty picker
		faith ?= {
			OR = {
				religious_head_title ?= { pam_head_of_faith_candidacy_valid_title_trigger = yes }
				any_faith_rite = {
					head_of_rite ?= {
						is_ruler = yes
						primary_title ?= { pam_head_of_faith_candidacy_valid_title_trigger = yes }
					}
				}
			}
		}
	}

	is_shown = {
		scope:secondary_recipient ?= {
			this != faith.main_rite.head_of_rite
			faith ?= scope:actor.faith
			is_clerical_appointment_valid_base_trigger = {
				CANDIDATE = scope:secondary_recipient
				TOP_LIEGE = scope:actor
			}
			NOR = {
				scope:actor.religious_head_or_challenger ?= this
				scope:secondary_recipient.religious_head_or_challenger ?= this
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			is_adult = yes
		}
		trigger_if = {
			limit = {
				exists = scope:target
			}
			influence_head_of_faith_candidacy_target_trigger = yes
			scope:secondary_recipient = {
				is_clerical_appointment_valid_trigger = {
					TITLE = scope:target
					CANDIDATE = scope:secondary_recipient
					TOP_LIEGE = scope:actor
				}
			}
		}
		pam_clerical_self_candidacy_restriction_trigger = yes
	}

	can_be_picked_title = {
		trigger_if = {
			limit = { exists = scope:secondary_recipient }
			custom_tooltip = {
				text = influence_clerical_candidacy_interaction_already_holds_title_tt
				scope:target = {
					holder != scope:secondary_recipient
				}
			}
		}
		influence_head_of_faith_candidacy_target_trigger = yes
		pam_clerical_self_candidacy_restriction_trigger = yes
	}

	has_valid_target_showing_failures_only = {
		exists = scope:target
		exists = scope:recipient
		# Dropping a title here instead of greying it out also keeps it out of the window's automatic selection, so the candidacy score values are never asked to price a title that does not use appointment succession
		scope:target = { pam_head_of_faith_candidacy_valid_title_trigger = yes }
	}

	redirect = {
		scope:recipient = { save_scope_as = secondary_recipient }
		scope:actor.faith.main_rite.head_of_rite ?= { save_scope_as = recipient }
	}

	can_send = {
		trigger_if = {
			limit = {
				OR = {
					scope:as_much_as_needed_candidacy_option ?= yes
					scope:major_candidacy_option ?= yes
					scope:medium_candidacy_option ?= yes
				}
			}
			scope:actor = {
				custom_tooltip = {
					text = support_candidacy_cap_reached_tt
					succession_appointment_score_invested = {
						title = scope:target
						candidate = scope:secondary_recipient
						value < scope:actor.appointment_investment_cap
					}
				}
			}
		}
	}

	auto_accept = yes

	send_option = {
		flag = as_much_as_needed_candidacy_option
		localization = as_much_as_needed_candidacy_option_desc
		is_valid = {
			trigger_if = {
				limit = {
					exists = scope:target
					exists = scope:secondary_recipient
				}
				custom_tooltip = {
					text = already_first_in_line_candidacy_option_desc
					NOT = { scope:target.current_heir = scope:secondary_recipient }
				}
			}
		}
	}
	send_option = {
		flag = major_candidacy_option
		localization = major_candidacy_option_desc
	}
	send_option = {
		flag = medium_candidacy_option
		localization = medium_candidacy_option_desc
		starts_enabled = { always = yes }
	}
	send_option = {
		flag = medium_candidacy_loss_option
		localization = medium_candidacy_loss_option_desc
	}
	send_option = {
		flag = major_candidacy_loss_option
		localization = major_candidacy_loss_option_desc
	}

	localization_values = {
		AS_MUCH_AS_NEEDED_CANDIDACY_OPTION = scope:actor.clerical_appointment_score_max_tt_value
		MAJOR_CANDIDACY_OPTION = scope:actor.clerical_appointment_score_major_tt_value
		MEDIUM_CANDIDACY_OPTION = scope:actor.clerical_appointment_score_medium_tt_value
		MEDIUM_CANDIDACY_LOSS_OPTION = scope:actor.appointment_score_medium_loss_tt_value
		MAJOR_CANDIDACY_LOSS_OPTION = scope:actor.appointment_score_major_loss_tt_value
	}

	cost = {
		piety = {
			value = {
				add = 0
				switch = {
					trigger = yes
					scope:as_much_as_needed_candidacy_option = {
						add = {
							value = pam_clerical_candidacy_outbid_piety_base_cost_value
						}
					}
					scope:major_candidacy_option = {
						add = { value = massive_piety_value }
					}
					scope:medium_candidacy_option = {
						add = { value = major_piety_value }
					}
					scope:medium_candidacy_loss_option = {
						add = { value = major_piety_value }
					}
					scope:major_candidacy_loss_option = {
						add = { value = massive_piety_value }
					}
				}
				multiply = scope:actor.pam_increase_theocratic_heir_candidacy_piety_cost_mult_value
			}
		}
	}

	on_accept = {
		switch = {
			trigger = yes
			scope:as_much_as_needed_candidacy_option = {
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = clerical_appointment_score_max_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = 15
				}
			}
			scope:major_candidacy_option = {
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_major_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = 10
				}
			}
			scope:medium_candidacy_option = {
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_medium_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = 5
				}
			}
			scope:medium_candidacy_loss_option = {
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_medium_loss_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = -10
				}
			}
			scope:major_candidacy_loss_option = {
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_major_loss_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = -20
				}
			}
		}

		if = {
			limit = {
				OR = {
					scope:as_much_as_needed_candidacy_option = yes
					scope:major_candidacy_option = yes
					scope:medium_candidacy_option = yes
				}
			}
			scope:secondary_recipient ?= {
				if = {
					limit = {
						this = scope:actor
						is_landless_adventurer = yes
						is_clergy = no
					}
					add_trait = cleric
				}
				if = {
					limit = { this != scope:actor }
					hidden_effect = {
						send_interface_message = {
							type = msg_candidacy_improved
							title = supported_candidacy_toast
							left_icon = scope:actor
							right_icon = scope:target
							show_as_tooltip = {
								scope:target = {
									change_appointment_investment = {
										target = scope:secondary_recipient
										investor = scope:actor
										value = scope:support_candidate_score
									}
								}
							}
						}
					}
					add_opinion = {
						modifier = supported_candidacy_opinion
						target = scope:actor
						opinion = scope:opinion_change_value
					}
				}
			}
		}
		else = {
			scope:secondary_recipient ?= {
				if = {
					limit = { this != scope:actor }
					hidden_effect = {
						send_interface_message = {
							type = msg_candidacy_harmed
							title = harmed_candidacy_toast
							left_icon = scope:actor
							right_icon = scope:target
							show_as_tooltip = {
								scope:target = {
									change_appointment_investment = {
										target = scope:secondary_recipient
										investor = scope:actor
										value = scope:support_candidate_score
									}
								}
							}
						}
					}
					add_opinion = {
						modifier = harmed_candidacy_opinion
						target = scope:actor
						opinion = scope:opinion_change_value
					}
				}
			}
		}

		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = influence_head_of_faith_candidacy_interaction_notification
				left_icon = scope:actor
				right_icon = scope:secondary_recipient
				scope:target = {
					change_appointment_investment = {
						target = scope:secondary_recipient
						investor = scope:actor
						value = scope:support_candidate_score
					}
				}
			}
		}
	}
}

# AI ONLY
support_clerical_candidacy_interaction = {
	icon = support_candidacy
	common_interaction = yes
	hidden = yes

	desc = support_clerical_candidacy_interaction_desc

	target_type = title
	target_source = actor
	target_filter = domain_clerical_regions

	can_be_picked_title = {
		# Only the capital see, so the search stays one title wide
		scope:actor.capital_county.clerical_region_title ?= scope:target
		trigger_if = {
			limit = { exists = scope:target.current_heir }
			scope:target.current_heir = {
				NOR = {
					this = scope:actor
					puppeteer ?= scope:actor
					has_relation_friend = scope:actor
					has_relation_lover = scope:actor
				}
			}
		}
		trigger_if = {
			limit = { exists = scope:secondary_recipient }
			is_clerical_appointment_valid_trigger = {
				TITLE = scope:target
				CANDIDATE = scope:secondary_recipient
				TOP_LIEGE = scope:actor
			}
		}
		scope:secondary_recipient = {
			custom_tooltip = {
				text = is_candidate_for_title_tt
				scope:target = {
					holder != scope:secondary_recipient
				}
				"appointment_candidate_accumulated_score(scope:target)" > 0
			}
		}
	}

	is_available = {
		can_influence_clerical_appointment_trigger = yes
		has_pam_dlc_trigger = yes
		piety >= major_piety_value
	}

	is_shown = {
		scope:secondary_recipient ?= {
			# Without this a Head of Rite backing themselves would send the interaction to themselves
			this != faith.main_rite.head_of_rite
			is_clerical_appointment_valid_base_trigger = {
				CANDIDATE = scope:secondary_recipient
				TOP_LIEGE = scope:actor
			}
			NOR = {
				scope:actor.religious_head_or_challenger ?= this
				scope:secondary_recipient.religious_head_or_challenger ?= this
			}
		}
	}

	redirect = {
		scope:recipient = { save_scope_as = secondary_recipient }
		scope:actor.faith.main_rite.head_of_rite ?= { save_scope_as = recipient }
	}

	populate_recipient_list = {
		scope:actor = {
			if = {
				limit = {
					is_clerical_appointment_valid_base_trigger = {
						CANDIDATE = this
						TOP_LIEGE = scope:actor
					}
				}
				add_to_list = characters
			}
			if = {
				limit = {
					puppet:theological_agent_puppet ?= {
						is_clerical_appointment_valid_base_trigger = {
							CANDIDATE = this
							TOP_LIEGE = scope:actor
						}
					}
				}
				puppet:theological_agent_puppet = { add_to_list = characters }
			}
			if = {
				limit = {
					puppet:external_theological_agent_puppet ?= {
						is_clerical_appointment_valid_base_trigger = {
							CANDIDATE = this
							TOP_LIEGE = scope:actor
						}
					}
				}
				puppet:external_theological_agent_puppet = { add_to_list = characters }
			}
			every_relation = {
				type = friend
				limit = {
					is_clerical_appointment_valid_base_trigger = {
						CANDIDATE = this
						TOP_LIEGE = scope:actor
					}
				}
				add_to_list = characters
			}
			every_relation = {
				type = lover
				limit = {
					is_clerical_appointment_valid_base_trigger = {
						CANDIDATE = this
						TOP_LIEGE = scope:actor
					}
				}
				add_to_list = characters
			}
		}
	}

	auto_accept = yes

	send_option = {
		flag = as_much_as_needed_candidacy_option
		localization = as_much_as_needed_candidacy_option_desc
	}
	send_option = {
		flag = major_candidacy_option
		localization = major_candidacy_option_desc
	}
	send_option = {
		flag = medium_candidacy_option
		localization = medium_candidacy_option_desc
	}

	cost = {
		piety = {
			value = {
				add = 0
				switch = {
					trigger = yes
					scope:as_much_as_needed_candidacy_option = {
						add = {
							value = pam_clerical_candidacy_outbid_piety_cost_value
							desc = BASE
						}
					}
					scope:major_candidacy_option = {
						add = {
							value = pam_clerical_candidacy_major_piety_cost_value
							desc = BASE
						}
					}
					scope:medium_candidacy_option = {
						add = {
							value = pam_clerical_candidacy_medium_piety_cost_value
							desc = BASE
						}
					}
				}
			}
		}
	}

	on_accept = {
		switch = {
			trigger = yes
			scope:as_much_as_needed_candidacy_option = {
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = clerical_appointment_score_max_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
			}
			scope:major_candidacy_option = {
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_major_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
			}
			scope:medium_candidacy_option = {
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_medium_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
			}
		}

		scope:target = {
			change_appointment_investment = {
				target = scope:secondary_recipient
				investor = scope:actor
				value = scope:support_candidate_score
			}
		}

		scope:secondary_recipient ?= {
			if = {
				limit = {
					this != scope:actor
					is_ai = no
				}
				hidden_effect = {
					send_interface_message = {
						type = msg_candidacy_improved
						title = supported_candidacy_toast
						left_icon = scope:actor
						right_icon = scope:target
						show_as_tooltip = {
							scope:target = {
								change_appointment_investment = {
									target = scope:secondary_recipient
									investor = scope:actor
									value = scope:support_candidate_score
								}
							}
						}
					}
				}
			}
		}

		# Christian Situation Catalysts
		if = {
			limit = {
				scope:actor = {
					NOR = {
						government_has_flag = government_is_ecclesiastical
						this = faith.main_rite.head_of_rite
					}
				}
				situation:the_christian_church ?= {
					situation_top_has_catalyst = catalyst_secular_influenced_clerical_candidacy
				}
			}
			situation:the_christian_church = {
				trigger_situation_catalyst = catalyst_secular_influenced_clerical_candidacy
			}
		}
		if = {
			limit = {
				scope:actor ?= scope:secondary_recipient
				scope:actor = {
					government_has_flag = government_is_ecclesiastical
				}
				situation:the_christian_church ?= {
					situation_top_has_catalyst = catalyst_clergy_influenced_own_candidacy
				}
			}
			situation:the_christian_church = {
				trigger_situation_catalyst = catalyst_clergy_influenced_own_candidacy
			}
		}
	}

	ai_targets = {
		ai_recipients = self
	}
	ai_targets = {
		ai_recipients = puppets
	}
	ai_targets = {
		ai_recipients = scripted_relations
		max = 20
	}

	# A crown returns to its capital see readily; a count has one see and rarely the piety to contest it
	ai_frequency_by_tier = {
		barony = 0
		county = 240
		duchy = 60
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	# Score the piety tiers explicitly so the AI does not fall back on send_option declaration order
	ai_will_do = {
		base = 0

		modifier = {
			scope:medium_candidacy_option = yes
			piety >= pam_clerical_candidacy_medium_piety_cost_value
			add = 100
		}
		modifier = {
			scope:major_candidacy_option = yes
			piety >= pam_clerical_candidacy_major_piety_cost_value
			add = 200
		}
		modifier = {
			scope:as_much_as_needed_candidacy_option = yes
			piety >= pam_clerical_candidacy_outbid_piety_cost_value
			add = 300
		}

		modifier = {
			exists = scope:secondary_recipient
			has_relation_rival = scope:secondary_recipient
			factor = 0
		}
	}
}

# AI ONLY - smear campaign against a clerical appointment candidate
harm_clerical_candidacy_interaction = {
	icon = harm_candidacy
	common_interaction = yes
	hidden = yes

	desc = harm_clerical_candidacy_interaction_desc

	target_type = title
	target_source = actor
	target_filter = domain_clerical_regions

	can_be_picked_title = {
		trigger_if = {
			limit = { exists = scope:secondary_recipient }
			is_clerical_appointment_valid_trigger = {
				TITLE = scope:target
				CANDIDATE = scope:secondary_recipient
				TOP_LIEGE = scope:actor
			}
		}
		scope:secondary_recipient = {
			custom_tooltip = {
				text = is_candidate_for_title_tt
				scope:target = {
					holder != scope:secondary_recipient
				}
				"appointment_candidate_accumulated_score(scope:target)" > 0
			}
		}
	}

	is_available = {
		ai_honor > 25
		OR = {
			has_trait = arbitrary
			has_trait = sadistic
			has_trait = deceitful
			has_trait = callous
			has_trait = vengeful
		}
		can_influence_clerical_appointment_trigger = yes
		#is_ai = yes
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:secondary_recipient ?= {
			is_clerical_appointment_valid_base_trigger = {
				CANDIDATE = scope:secondary_recipient
				TOP_LIEGE = scope:actor
			}
		}
	}

	is_valid_showing_failures_only = {
		# When realms get really large, the AI needs a fixed pool of characters to promote
		# Otherwise performance tanks significantly in the form of 'stutters' or smaller freezes
		scope:secondary_recipient ?= {
			trigger_if = {
				limit = {
					scope:actor.realm_size >= 250
				}
				static_group_filter = {
					group = ai_filter
					match = {
						value = 1
						subtract = {
							add = scope:actor.realm_size
							multiply = 0.001
							multiply = 3
							min = 0.1
							max = 0.9
						}
					}
				}
			}
		}
		scope:actor = {
			piety >= major_piety_value
		}
	}

	redirect = {
		scope:recipient = { save_scope_as = secondary_recipient }
		scope:actor.faith.main_rite.head_of_rite ?= { save_scope_as = recipient }
	}

	populate_recipient_list = {
		scope:actor = {
			every_relation = {
				type = rival
				type = nemesis
				limit = {
					is_clerical_appointment_valid_base_trigger = {
						CANDIDATE = this
						TOP_LIEGE = scope:actor
					}
					NOT = { is_close_or_extended_family_of = scope:actor }
				}
				add_to_list = characters
			}
			house ?= {
				every_house_relation = {
					limit = {
						OR = {
							has_house_relation_level = quarrel
							has_house_relation_level = rivalry
							has_house_relation_level = feud
						}
					}
					every_relation_house = {
						house_head = {
							every_close_family_member = {
								limit = {
									is_clerical_appointment_valid_base_trigger = {
										CANDIDATE = this
										TOP_LIEGE = scope:actor
									}
									NOT = { is_close_or_extended_family_of = scope:actor }
								}
								add_to_list = characters
							}
						}
					}
				}
			}
		}
	}

	auto_accept = yes

	send_option = {
		flag = minor_candidacy_harm_option
		localization = minor_candidacy_harm_option_desc
		starts_enabled = { always = yes }
	}
	send_option = {
		flag = medium_candidacy_harm_option
		localization = medium_candidacy_harm_option_desc
	}
	send_option = {
		flag = major_candidacy_harm_option
		localization = major_candidacy_harm_option_desc
	}

	localization_values = {
		MINOR_CANDIDACY_HARM_OPTION = scope:actor.clerical_appointment_score_minor_loss_tt_value
		MEDIUM_CANDIDACY_HARM_OPTION = scope:actor.clerical_appointment_score_medium_loss_tt_value
		MAJOR_CANDIDACY_HARM_OPTION = scope:actor.clerical_appointment_score_major_loss_tt_value
	}

	cost = {
		piety = {
			value = {
				add = 0
				switch = {
					trigger = yes
					scope:minor_candidacy_harm_option = {
						add = {
							value = minor_piety_value
							desc = BASE
						}
					}
					scope:medium_candidacy_harm_option = {
						add = {
							value = major_piety_value
							desc = BASE
						}
					}
					scope:major_candidacy_harm_option = {
						add = {
							value = massive_piety_value
							desc = BASE
						}
					}
				}
				multiply = scope:actor.pam_increase_theocratic_heir_candidacy_piety_cost_mult_value
			}
		}
	}

	on_accept = {
		switch = {
			trigger = yes
			scope:minor_candidacy_harm_option = {
				save_scope_value_as = {
					name = harm_candidate_score
					value = {
						value = appointment_score_minor_loss_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = -5
				}
			}
			scope:medium_candidacy_harm_option = {
				save_scope_value_as = {
					name = harm_candidate_score
					value = {
						value = appointment_score_medium_loss_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = -15
				}
			}
			scope:major_candidacy_harm_option = {
				save_scope_value_as = {
					name = harm_candidate_score
					value = {
						value = appointment_score_major_loss_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
						multiply = scope:actor.pam_theocratic_candidacy_situation_multiplier_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = -30
				}
			}
		}

		scope:target = {
			change_appointment_investment = {
				target = scope:secondary_recipient
				investor = scope:actor
				value = scope:harm_candidate_score
			}
		}

		if = {
			limit = {
				scope:secondary_recipient = { this != scope:actor }
			}
			scope:secondary_recipient = {
				add_opinion = {
					modifier = harmed_candidacy_opinion
					target = scope:actor
					opinion = scope:opinion_change_value
				}
				if = {
					limit = {
						is_ai = no
					}
					hidden_effect = {
						send_interface_message = {
							type = msg_candidacy_harmed
							title = harmed_candidacy_toast
							left_icon = scope:actor
							right_icon = scope:target
							show_as_tooltip = {
								scope:target = {
									change_appointment_investment = {
										target = scope:secondary_recipient
										investor = scope:actor
										value = scope:harm_candidate_score
									}
								}
							}
						}
					}
				}
			}
			if = {
				limit = {
					scope:actor = { is_ai = no }
				}
				scope:actor = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = harm_candidate_rival_progress_toast
						left_icon = scope:secondary_recipient
						scope:secondary_recipient = {
							progress_towards_rival_effect = {
								REASON = rival_harmed_candidacy
								CHARACTER = scope:actor
								OPINION = 0
							}
						}
					}
				}
			}
		}

		# Christian Situation Catalysts
		if = {
			limit = {
				scope:actor = {
					NOR = {
						government_has_flag = government_is_ecclesiastical
						this = faith.main_rite.head_of_rite
					}
				}
				situation:the_christian_church ?= {
					situation_top_has_catalyst = catalyst_secular_influenced_clerical_candidacy
				}
			}
			situation:the_christian_church = {
				trigger_situation_catalyst = catalyst_secular_influenced_clerical_candidacy
			}
		}
	}

	ai_targets = {
		ai_recipients = scripted_relations
	}
	ai_targets = {
		ai_recipients = family
		ai_recipients = courtiers
		ai_recipients = vassals
		max = 20
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 360
		duchy = 180
		kingdom = 180
		empire = 180
		hegemony = 180
	}

	ai_will_do = {
		base = 0
		modifier = {
			scope:actor = {
				has_relation_rival = scope:secondary_recipient
			}
			add = 100
		}
		modifier = {
			scope:actor = {
				has_relation_nemesis = scope:secondary_recipient
			}
			add = 150
		}
		modifier = {
			scope:actor = {
				opinion = {
					target = scope:secondary_recipient
					value < medium_positive_opinion
				}
			}
			add = 20
		}
		modifier = {
			scope:secondary_recipient ?= {
				is_close_family_of = scope:actor
			}
			add = -50
		}
		modifier = {
			scope:secondary_recipient ?= {
				is_extended_family_of = scope:actor
			}
			add = -25
		}
		modifier = {
			scope:actor = {
				OR = {
					has_trait = ambitious
					has_trait = callous
					has_trait = deceitful
				}
			}
			add = 40
		}
		modifier = {
			scope:actor = {
				has_usable_hook = scope:secondary_recipient
			}
			add = -10
		}
		modifier = {
			scope:actor = {
				OR = {
					has_relation_friend = scope:secondary_recipient
					has_relation_lover = scope:secondary_recipient
				}
			}
			factor = 0
		}
	}
}

request_realm_priest_replacement_interaction = {
	category = interaction_category_religion
	icon = icon_request_priest
	interface_priority = 100
	common_interaction = yes
	notification_text = REQUEST_REALM_PRIEST_REPLACEMENT_NOTIFICATION

	desc = request_realm_priest_replacement_interaction_desc

	redirect = {
		# Prioritize direct superior of chaplain, over e.g. head of faith
		# But still allow right clicking on anyone in religious hierachy
		scope:actor = {
			if = {
				limit = {
					# Standard recipient triggers are true...
					can_request_priest_from_recipient_trigger = { RECIPIENT = scope:recipient }
				}
				# A realm under an antipope has only them to ask, so anyone else clicked is left to fail validity
				if = {
					limit = { is_following_religious_head_challenger = yes }
					if = {
						limit = { cp:councillor_court_chaplain ?= scope:recipient }
						religious_head_or_challenger ?= { save_scope_as = recipient }
					}
				}
				# Ensure direct superior of chaplain is always prioritized...
				else_if = {
					limit = {
						# Selected recipient is not direct superior of chaplain
						exists = cp:councillor_court_chaplain.superior
						cp:councillor_court_chaplain.superior != scope:recipient
					}
					cp:councillor_court_chaplain.superior = { save_scope_as = recipient }
				}
				# ...otherwise ensure the recipient is not the current chaplain
				else_if = {
					limit = { cp:councillor_court_chaplain ?= scope:recipient }
					if = {
						limit = { exists = faith.religious_head }
						faith.religious_head = { save_scope_as = recipient }
					}
					else_if = {
						limit = { exists = faith.main_rite.head_of_rite }
						faith.main_rite.head_of_rite = { save_scope_as = recipient }
					}
				}
			}
		}
	}

	populate_recipient_list = {
		scope:actor = {
			every_vassal_or_below = {
				every_courtier = { # All non-councillor realm courtiers of the actor's vassals
					limit = {
						can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
						is_councillor = no
					}
					add_to_list = characters
				}
			}
			every_courtier = { # All non-councillor realm courtiers of the actor
				limit = {
					can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
					is_councillor = no
				}
				add_to_list = characters
			}
		}
		scope:recipient = {
			every_vassal_or_below = {
				every_courtier = { # All non-councillor realm courtiers of the recipient's vassals
					limit = {
						can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
						is_councillor = no
					}
					add_to_list = characters
				}
			}
			every_courtier = { # All non-councillor realm courtiers of the recipient
				limit = {
					can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
					is_councillor = no
				}
				add_to_list = characters
			}
		}
		scope:actor = {
			every_vassal_or_below = { # All non-councillor theocratic vassals of the actor
				limit = {
					government_has_flag = government_is_theocracy
					can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
					is_councillor = no
				}
				add_to_list = characters
			}
			#Monk house members too!
			house ?= {
				every_house_member = {
					limit = {
						has_trait = devoted
						in_diplomatic_range = scope:actor
						is_adult = yes
						is_ruler = no
						can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
						is_councillor = no
						trigger_if = {
							limit = {
								exists = liege
								liege = {
									NOT = {
										this = scope:actor
									}
								}
							}
							liege = {
								is_ai = yes
							}
						}
						NOT = {
							has_relation_rival = scope:actor
						}
					}
					add_to_list = characters
				}
			}
			every_child = {
				limit = {
					has_trait = devoted	
				}
			}
		}
	}

	is_available = {
		# Temporal/Conditional use council Appoint, which fires on_fired_from_position instead
		NOT = { faith = { has_doctrine_parameter = clerical_appointment_ruler_can_replace_ecc } }
		government_allows = council
		# Nomads have no Court Chaplain position to replace, so they cannot request a new Realm Priest
		NOT = { government_has_flag = government_is_nomadic }
		# The Minister of Rites is appointed through the ministry, not by petitioning the clergy
		tgp_has_access_to_ministry_trigger = no
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		# The Head of Faith appoints their own chaplain freely via the council instead of petitioning themselves
		scope:recipient != scope:actor
		# Allow right clicking on anyone in religious hierachy
		scope:actor = {
			can_request_priest_from_recipient_trigger = { RECIPIENT = scope:recipient }
		}
	}

	cooldown_against_recipient = { years = 5 }

	is_valid_showing_failures_only = {
		scope:actor = {
			trigger_if = {
				limit = {
					NOT = {
						government_has_flag = government_is_theocracy
					}
				}
				custom_tooltip = {
					text = piety_level_or_external_puppet_req_tt
					OR = {
						exists = puppet:external_theological_agent_puppet
						piety_level >= 3
					}
				}
			}
			trigger_else = {
				piety_level >= 1
			}
			pam_antipope_clerical_request_trigger = { RECIPIENT = scope:recipient }
			custom_tooltip = {
				text = pam_blocked_by_promised_pilgrimage_tt
				NOT = { has_character_modifier = promised_pilgrimage_to_clergy_modifier }
			}
		}
		custom_tooltip = {
			text = recipient_will_not_replace_self_tt
			scope:recipient != scope:actor.cp:councillor_court_chaplain
		}
	}

	can_send = {
		custom_tooltip = {
			text = recipient_will_not_replace_self_tt
			scope:recipient != scope:actor.cp:councillor_court_chaplain
		}
	}

	cost = {
		piety = {
			value = 0
			# Change the piety loss amount based on the candidate's education level
			if = {
				limit = {
					scope:secondary_recipient ?= { has_education_rank_trigger = { RANK = 1 OPERATOR = equals } }
				}
				add = minor_piety_value
			}
			if = {
				limit = {
					scope:secondary_recipient ?= { has_education_rank_trigger = { RANK = 2 OPERATOR = equals } }
				}
				add = medium_piety_value
			}
			if = {
				limit = {
					scope:secondary_recipient ?= { has_education_rank_trigger = { RANK = 3 OPERATOR = equals } }
				}
				add = major_piety_value
			}
			if = {
				limit = {
					scope:secondary_recipient ?= { has_education_rank_trigger = { RANK = 4 OPERATOR = equals } }
				}
				add = massive_piety_value
			}
			if = {
				limit = {
					scope:secondary_recipient ?= { has_education_rank_trigger = { RANK = 5 OPERATOR = equals } }
				}
				add = monumental_piety_value
			}
			#Costs more to send for your monk relatives
			if = {
				limit = {
					scope:secondary_recipient = {
						NOR = {
							is_vassal_or_below_of = scope:actor
							is_courtier_of = scope:actor
						}
					}
				}
				multiply = 1.5
			}
			if = {
				limit = {
					scope:actor = {
						domicile ?= { has_domicile_parameter = estate_cheaper_realm_priest }
					}
				}
				multiply = ecclesiastical_domicile_cheaper_realm_priest_mult
			}
		}
	}

	on_accept = {
		scope:actor = {
			# Remove the current realm priest and make the candidate the realm priest
			if = {
				limit = {
					scope:secondary_recipient = {
						NOT = {
							is_courtier_of = scope:actor
						}
						is_ruler = no
					}
				}
				add_courtier = scope:secondary_recipient # Move the character to the court first if he's from another court and not a ruler.
			}
			cp:councillor_court_chaplain = {
				save_scope_as = old_chaplain
			}
			# Flag so on_fired_from_position does not treat this as the crown acting
			add_character_flag = { flag = pam_church_replacing_realm_priest days = 1 }
			assign_councillor_type = {
				type = councillor_court_chaplain
				remove_existing_councillor = yes
				target = scope:secondary_recipient
			}
			remove_character_flag = pam_church_replacing_realm_priest
			send_interface_toast = {
				type = event_toast_effect_good
				title = new_realm_priest_toast_title
				left_icon = scope:actor
				right_icon = scope:secondary_recipient
				# Make sure the candidate is grateful
				scope:actor = {
					reverse_add_opinion = {
						target = scope:secondary_recipient
						modifier = grateful_opinion
						opinion = 40
					}
				}
				if = {
					limit = {
						scope:use_hook = yes
						has_usable_hook = scope:recipient
					}
					use_hook = scope:recipient
				}
			}
			scope:old_chaplain = {
				add_opinion = { # Make sure your kicked realm priest is pissed
					target = scope:actor
					modifier = fp3_resentful_opinion
					opinion = -40
				}
			}
		}
		pam_offer_pilgrimage_effect = {
			ACTOR = scope:actor
			CLERIC = scope:recipient
		}
		# Catalysts
		if = {
			limit = {
				scope:actor.religion = religion:christianity_religion
				# Only rulers actually taking part in the situation can move it
				scope:actor = { exists = top_participant_group:the_christian_church }
				situation:the_christian_church ?= { situation_top_has_catalyst = catalyst_the_christian_church_requested_realm_priest_replacement }
			}
			situation:the_christian_church = { trigger_situation_catalyst = catalyst_the_christian_church_requested_realm_priest_replacement }
		}
	}

	on_decline = {

	}

	auto_accept = {
		# Using a hook should make him auto accept
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:use_hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
		}
	}

	ai_accept = {
		base = 0

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:puppet_or_actor
			RECIPIENT = scope:recipient
		}

		# Weak hook: extra points
		modifier = {
			scope:use_hook = yes
			add = 200
			scope:actor = { NOT = { has_strong_hook = scope:recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}

		modifier = {
			add = pam_offer_pilgrimage_acceptance_value
			scope:offer_pilgrimage = yes
			desc = OFFER_PILGRIMAGE_INTERACTION_OPTION_REASON
		}

		# Respect the liege
		modifier = {
			add = 100
			scope:recipient = { target_is_liege_or_above = scope:actor }
			desc = LIEGE_REASON
		}

		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_1
			desc = ESTATE_REALM_PRIEST_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_easier_realm_priest_replacement_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_2
			desc = ESTATE_REALM_PRIEST_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_easier_realm_priest_replacement_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_3
			desc = ESTATE_REALM_PRIEST_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_easier_realm_priest_replacement_3
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_1
			desc = ESTATE_SEMINARY_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_confessor_seminary_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_2
			desc = ESTATE_SEMINARY_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_confessor_seminary_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_3
			desc = ESTATE_SEMINARY_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_confessor_seminary_3
				}
			}
		}
		ecclesiastical_domicile_cathedral_awe_modifier = yes

		# Actor is from the recipient's house
		modifier = {
			add = 10
			exists = scope:actor.house
			scope:recipient = {
				OR = {
					is_close_family_of = scope:actor
					is_extended_family_of = scope:actor
				}
			}
			desc = YOU_ARE_MY_HOUSE_MEMBER
		}

		# Candidate is from the recipient's house
		modifier = {
			add = 10
			exists = scope:secondary_recipient
			exists = scope:secondary_recipient.house
			scope:recipient = {
				OR = {
					is_close_family_of = scope:secondary_recipient
					is_extended_family_of = scope:secondary_recipient
				}
			}
			desc = THEY_ARE_MY_HOUSE_MEMBER
		}

		# I have sinful traits
		modifier = {
			add = {
				add = -10
				multiply = scope:actor.num_sinful_traits
			}
			scope:actor.num_sinful_traits > 0
			desc = I_AM_SINFUL
		}

		# Candidate has sinful traits
		modifier = {
			exists = scope:secondary_recipient
			add = {
				add = -10
				multiply = scope:secondary_recipient.num_sinful_traits
			}
			scope:secondary_recipient.num_sinful_traits > 0
			desc = THEY_ARE_SINFUL
		}

		# I have virtuous traits
		modifier = {
			add = {
				add = 10
				multiply = scope:actor.num_virtuous_traits
			}
			scope:actor.num_virtuous_traits > 0
			desc = I_AM_VIRTUOUS
		}

		# Candidate has virtuous traits
		modifier = {
			exists = scope:secondary_recipient
			add = {
				add = 10
				multiply = scope:secondary_recipient.num_virtuous_traits
			}
			scope:secondary_recipient.num_virtuous_traits > 0
			desc = THEY_ARE_VIRTUOUS
		}

		# Religious superior's opinion of the actor matters!
		opinion_modifier = {
			opinion_target = scope:actor
			who = scope:recipient
			multiplier = 1
			desc = AI_OPINION_REASON
		}

		# Religious Superior likes candidate more than the realm priest
		modifier = {
			add = 20
			exists = scope:secondary_recipient
			scope:recipient = {
				save_temporary_opinion_value_as = {
					name = secondary_recipient_opinion
					target = scope:secondary_recipient
				}
				save_temporary_opinion_value_as = {
					name = realm_priest_opinion
					target = scope:actor.cp:councillor_court_chaplain
				}
			}
			scope:secondary_recipient_opinion > {
			   add = scope:realm_priest_opinion
			   add = 20
			}
			desc = AI_OPINION_REASON_CANDIDATE_OVER_REALM_PRIEST
		}

		# Religious Superior likes realm priest more than the candidate
		modifier = {
			add = -20
			exists = scope:secondary_recipient
			scope:recipient = {
				save_temporary_opinion_value_as = {
					name = secondary_recipient_opinion
					target = scope:secondary_recipient
				}
				save_temporary_opinion_value_as = {
					name = realm_priest_opinion
					target = scope:actor.cp:councillor_court_chaplain
				}
			}
			scope:realm_priest_opinion > {
			   add = scope:secondary_recipient_opinion
			   add = 20
			}
			desc = AI_OPINION_REASON_REALM_PRIEST_OVER_CANDIDATE
		}

		modifier = { # A trait in common with the candidate
			add = 5
			exists = scope:secondary_recipient
			scope:recipient = {
				number_of_personality_traits_in_common = {
					target = scope:secondary_recipient
					value = 1
				}
			}
			desc = AI_COMMON_TRAITS
		}

		modifier = { # Two trait in common
			add = 10
			exists = scope:secondary_recipient
			scope:recipient = {
				number_of_personality_traits_in_common = {
					target = scope:secondary_recipient
					value = 2
				}
			}
			desc = AI_COMMON_TRAITS
		}

		modifier = { # Three traits in common
			add = 15
			exists = scope:secondary_recipient
			scope:recipient = {
				number_of_personality_traits_in_common = {
					target = scope:secondary_recipient
					value = 3
				}
			}
			desc = AI_COMMON_TRAITS
		}

		# Modifier based on Piety Level of the actor
		modifier = {
			add = {
				add = 5
				multiply = scope:actor.piety_level
			}
			scope:actor.piety_level > 1
			desc = I_AM_PIOUS
		}

		# Modifier based on Piety Level of the candidate
		modifier = {
			exists = scope:secondary_recipient
			add = {
				add = 5
				multiply = scope:secondary_recipient.piety_level
			}
			scope:secondary_recipient.piety_level > 1
			desc = THEY_ARE_PIOUS
		}

		# More likely to accept if you have an alliance
		modifier = {
			add = 40
			scope:actor = { is_allied_to = scope:recipient }
			desc = AI_HAS_ALLIANCE
		}

		# Fs
		modifier = {
			add = 25
			scope:recipient = {
				has_relation_friend = scope:actor
			}
			desc = WE_ARE_FRIENDS
		}

		# BFFs
		modifier = {
			add = 50
			scope:recipient = {
				has_relation_best_friend = scope:actor
			}
			desc = WE_ARE_BEST_FRIENDS
		}

		# Take dread into account
		modifier = {
			add = 50
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}

		modifier = {
			add = 100
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}

		# Below 10 Learning for negative, Above 10 Learning for positive
		modifier = {
			add = {
				value = scope:secondary_recipient.learning
				subtract = 10
				multiply = 2
			}
			trigger = {
				scope:secondary_recipient ?= {
					learning != 10
				}
			}
			desc = THEY_HAVE_LEARNING_SKILL_REASON
		}

		# Is a monk
		modifier = {
			add = 25
			scope:secondary_recipient ?= {
				has_trait = erudite
			}
			desc = THEY_HAVE_ERUDITE_TRAIT
		}
	}

	send_option = {
		is_shown = {
			scope:recipient != scope:actor
		}
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
			trigger_if = {
				limit = {
					scope:recipient = {
						is_ai = no
					}
				}
				scope:actor = { is_ai = no }
			}
		}
		flag = use_hook
		localization = EDUCATION_HOOK
	}

	send_option = {
		is_shown = {
			pam_offer_pilgrimage_option_shown_trigger = { ACTOR = scope:actor }
		}
		is_valid = {
			pam_offer_pilgrimage_option_valid_trigger = { ACTOR = scope:actor }
		}
		flag = offer_pilgrimage
		localization = OFFER_PILGRIMAGE_INTERACTION_OPTION
	}

	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}

	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	ai_targets = {
		ai_recipients = realm_priest_superior
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 60
		duchy = 60
		kingdom = 60
		empire = 60
		hegemony = 60
	}

	ai_will_do = {
		base = 0
		opinion_modifier = { # I dislike my realm priest
			opinion_target = scope:actor.cp:councillor_court_chaplain
			who = scope:actor
			multiplier = -1
		}
		opinion_modifier = { # My realm priest dislikes me
			opinion_target = scope:actor
			who = scope:actor.cp:councillor_court_chaplain
			multiplier = -1
		}
		modifier = {
			add = 50
			desc = request_realm_priest_replacement_ai_different_rite
			exists = scope:actor.cp:councillor_court_chaplain
			scope:actor.cp:councillor_court_chaplain.rite != scope:actor.rite
		}
	}
}

# Sway to Rite is split three ways for performance, like the Demand Conversion family
# Persuade one of your own courtiers to adopt your rite
sway_courtier_to_my_rite_interaction = {
	category = interaction_category_religion
	special_interaction = rite_conversion
	icon = icon_rite
	interface_priority = 45
	common_interaction = yes

	ai_maybe = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes
	notification_text = sway_ruler_to_my_rite_interaction_notification

	desc = sway_ruler_to_my_rite_interaction_desc

	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			is_adult = yes
			is_incapable = no
		}
	}

	is_shown = {
		scope:recipient = {
			is_courtier_of = scope:puppet_or_actor
		}
		scope:puppet_or_actor ?= {
			faith = scope:recipient.faith
			rite != scope:recipient.rite
		}
	}

	cooldown_against_recipient = { years = 5 }

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			NOR = {
				has_trait = incapable
				is_adult = no
			}
		}
		scope:recipient = {
			NOR = {
				is_adult = no
				has_trait = incapable
				custom_tooltip = {
					text = sway_ruler_to_my_rite_interaction_hor_tt
					rite.head_of_rite ?= this
					NOT = { pam_sway_to_rite_head_of_faith_reclaims_trigger = { ACTOR = scope:puppet_or_actor } }
				}
				custom_tooltip = {
					text = sway_ruler_to_my_rite_interaction_hof_tt
					OR = {
						scope:puppet_or_actor.religious_head_or_challenger ?= this
						primary_title ?= { is_head_of_faith = yes }
					}
				}
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= pam_sway_ruler_to_my_rite_cost_value
			}
		}
	}

	cost = {
		piety = {
			value = pam_sway_ruler_to_my_rite_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
			#Free for holy order leaders spreading beliefs
			if = {
				limit = {
					scope:holy_order_leader ?= this
					exists = scope:order_tenet
				}
				multiply = 0
			}
		}
	}

	#Use hook
	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				has_usable_hook = scope:recipient
			}
			scope:recipient = {
				NOT = { is_imprisoned_by = scope:puppet_or_actor }
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:puppet_or_actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:puppet_or_actor
			object = scope:recipient
			scope:hook = yes
			scope:puppet_or_actor = { has_strong_hook = scope:recipient }
			NOT = { scope:recipient = { has_character_flag = ai_will_not_convert } }
		}
	}

	on_accept = {
		pam_sway_to_rite_on_accept_effect = yes
	}

	on_decline = {
		pam_sway_to_rite_on_decline_effect = yes
	}

	ai_accept = {
		base = -15

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:puppet_or_actor
			RECIPIENT = scope:recipient
		}

		religion_sway_to_rite_default_modifier = yes
		modifier = { # The Head of Faith calling them back to the mainline rite eases the Head of Rite refusal
			add = 100
			scope:recipient.rite.head_of_rite ?= scope:recipient
			pam_sway_to_rite_head_of_faith_reclaims_trigger = { ACTOR = scope:puppet_or_actor }
			desc = PAM_SWAY_HEAD_OF_FAITH_REASON
		}
		modifier = {
			desc = ASK_FOR_CONVERSION_RECIPIENT_WILL_NOT_ACCEPT
			add = -1500
			scope:recipient = {
				has_character_flag = ai_will_not_convert
			}
		}
	}

	ai_targets = {
		ai_recipients = courtiers
		max = 5
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 120
		duchy = 36
		kingdom = 24
		empire = 24
		hegemony = 24
	}

	ai_will_do = {
		base = 25
		modifier = {
			scope:hook = yes
			add = 50
		}
		modifier = {
			add = 50
			scope:puppet_or_actor = {
				has_trait = zealous
			}
		}
		modifier = {
			add = -50
			scope:puppet_or_actor = {
				has_trait = cynical
			}
		}
		modifier = { # Try to rigorously convert your heir so all efforts won't go to waste on succession
			add = 100
			scope:recipient = {
				is_primary_heir_of = scope:puppet_or_actor
			}
		}
		modifier = { # More likely against close family members
			add = 50
			scope:recipient = {
				is_close_family_of = scope:puppet_or_actor
			}
		}
		modifier = { # HoRs actually hustle
			add = 50
			scope:puppet_or_actor.rite.head_of_rite ?= scope:puppet_or_actor
		}
		modifier = { # More likely if the government is religious
			add = 50
			scope:puppet_or_actor = {
				government_is_religious_trigger = yes
			}
		}
		modifier = { # Heresiarchs are able to spread their rites easily
			add = 1000
			scope:puppet_or_actor = {
				OR = {
					has_trait = heresiarch
					has_trait = herald
				}
			}
		}
	}
}

# Persuade a subject, tributary, or landed member of your house to adopt your rite
sway_vassal_to_my_rite_interaction = {
	category = interaction_category_religion
	special_interaction = rite_conversion
	icon = icon_rite
	interface_priority = 45
	common_interaction = yes

	use_diplomatic_range = yes
	ai_maybe = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes
	notification_text = sway_ruler_to_my_rite_interaction_notification

	desc = sway_ruler_to_my_rite_interaction_desc

	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			is_adult = yes
			is_incapable = no
		}
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			faith = scope:recipient.faith
			rite != scope:recipient.rite
		}
		scope:puppet_or_actor != scope:recipient
		scope:recipient = {
			NOT = { is_courtier_of = scope:puppet_or_actor }
			OR = {
				target_is_liege_or_above = scope:puppet_or_actor
				is_tributary_of = scope:puppet_or_actor
				pam_rite_sway_house_lane_trigger = {
					ACTOR = scope:puppet_or_actor
					RECIPIENT = this
				}
			}
		}
	}

	cooldown_against_recipient = { years = 5 }

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			NOR = {
				is_at_war_with = scope:recipient
				has_trait = incapable
				is_adult = no
			}
		}
		scope:recipient = {
			NOR = {
				is_adult = no
				has_trait = incapable
				custom_tooltip = {
					text = sway_ruler_to_my_rite_interaction_hor_tt
					rite.head_of_rite ?= this
					NOT = { pam_sway_to_rite_head_of_faith_reclaims_trigger = { ACTOR = scope:puppet_or_actor } }
				}
				custom_tooltip = {
					text = sway_ruler_to_my_rite_interaction_hof_tt
					OR = {
						scope:puppet_or_actor.religious_head_or_challenger ?= this
						primary_title ?= { is_head_of_faith = yes }
					}
				}
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= pam_sway_ruler_to_my_rite_cost_value
			}
		}
	}

	cost = {
		piety = {
			value = pam_sway_ruler_to_my_rite_cost_value
			if = {
				limit = { scope:pam_sway_disputation ?= yes }
				add = medium_piety_value
			}
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	#Use hook
	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				has_usable_hook = scope:recipient
			}
			scope:recipient = {
				NOT = { is_imprisoned_by = scope:puppet_or_actor }
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	# Clergy inducements are shared with the outreach variant so vassal sway is never a worse toolkit
	# Endow their church - paid to the recipient on acceptance
	send_option = {
		is_shown = {
			scope:puppet_or_actor ?= {
				pam_is_clergy_ruler_trigger = yes
				has_treasury = yes
			}
			scope:puppet_or_actor = scope:actor
			trigger_if = {
				limit = { scope:actor = { is_ai = yes } }
				scope:recipient = {
					OR = {
						is_ai = no
						any_held_title = { has_clerical_region = yes }
						highest_held_title_tier >= tier_kingdom
					}
				}
			}
		}
		is_valid = {
			scope:puppet_or_actor = {
				treasury >= pam_sway_to_rite_endowment_cost_value
			}
		}
		flag = pam_sway_endowment
		localization = PAM_SWAY_TO_RITE_ENDOWMENT_OPTION
	}
	# Theological disputation - unlocked by scholarly renown, costs extra piety
	send_option = {
		is_shown = {
			scope:puppet_or_actor ?= {
				pam_is_clergy_ruler_trigger = yes
			}
			scope:puppet_or_actor = scope:actor
		}
		is_valid = {
			custom_tooltip = {
				text = PAM_SWAY_TO_RITE_DISPUTATION_REQUIRES_SCHOLAR
				scope:puppet_or_actor = {
					has_trait = lifestyle_scholar
					has_trait_xp = {
						trait = lifestyle_scholar
						value >= 60
					}
				}
			}
			scope:puppet_or_actor = {
				piety >= pam_sway_to_rite_disputation_piety_total_value
			}
		}
		flag = pam_sway_disputation
		localization = PAM_SWAY_TO_RITE_DISPUTATION_OPTION
	}
	# Pledge a favor - only worth anything to a prelate who can call it in against our treasury
	send_option = {
		is_shown = {
			scope:puppet_or_actor ?= {
				pam_is_clergy_ruler_trigger = yes
				has_treasury = yes
			}
			scope:puppet_or_actor = scope:actor
			scope:recipient = {
				government_has_flag = government_is_ecclesiastical
			}
			trigger_if = {
				limit = { scope:actor = { is_ai = yes } }
				scope:actor = { has_trait = trusting }
			}
		}
		is_valid = {
			scope:recipient = {
				can_add_hook = {
					target = scope:puppet_or_actor
					type = favor_hook
				}
			}
		}
		flag = pam_sway_pledge_favor
		localization = PAM_SWAY_TO_RITE_PLEDGE_FAVOR_OPTION
	}
	should_use_extra_icon = {
		scope:puppet_or_actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:puppet_or_actor
			object = scope:recipient
			scope:hook = yes
			scope:puppet_or_actor = { has_strong_hook = scope:recipient }
			NOT = { scope:recipient = { has_character_flag = ai_will_not_convert } }
		}
	}

	on_accept = {
		pam_sway_to_rite_on_accept_effect = yes
	}

	on_decline = {
		pam_sway_to_rite_on_decline_effect = yes
	}

	ai_accept = {
		base = -15

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:puppet_or_actor
			RECIPIENT = scope:recipient
		}

		religion_sway_to_rite_default_modifier = yes
		modifier = { # The Head of Faith calling them back to the mainline rite eases the Head of Rite refusal
			add = 100
			scope:recipient.rite.head_of_rite ?= scope:recipient
			pam_sway_to_rite_head_of_faith_reclaims_trigger = { ACTOR = scope:puppet_or_actor }
			desc = PAM_SWAY_HEAD_OF_FAITH_REASON
		}
		modifier = {
			desc = ASK_FOR_CONVERSION_RECIPIENT_WILL_NOT_ACCEPT
			add = -1500
			scope:recipient = {
				has_character_flag = ai_will_not_convert
			}
		}
		modifier = { # Endowing their church sweetens the petition
			add = 25
			scope:pam_sway_endowment ?= yes
			desc = PAM_SWAY_ENDOWMENT_REASON
		}
		modifier = { # Doubly so when our rite blesses such transactions
			add = 20
			scope:pam_sway_endowment ?= yes
			pam_actor_has_simony_trigger = yes
			desc = PAM_SWAY_ENDOWMENT_SIMONY_REASON
		}
		modifier = { # Hard to gainsay a doctor of scripture in open disputation
			add = {
				value = scope:puppet_or_actor.learning
				subtract = scope:recipient.learning
				multiply = 2
				min = 0
				add = 20
			}
			scope:pam_sway_disputation ?= yes
			desc = PAM_SWAY_DISPUTATION_REASON
		}
		modifier = { # They would hold a favor over us
			add = 30
			scope:pam_sway_pledge_favor ?= yes
			desc = PAM_SWAY_PLEDGE_FAVOR_REASON
		}
		modifier = { # Prelate recipients resist; eases as their diocese converts to our rite
			add = {
				value = -75
				add = pam_sway_to_rite_diocese_momentum_value
			}
			scope:puppet_or_actor ?= { pam_is_clergy_ruler_trigger = yes }
			scope:recipient = {
				any_held_title = { has_clerical_region = yes }
			}
			desc = PAM_SWAY_RECIPIENT_PRELATE_REASON
		}
		modifier = { # Their own diocese is already turning to our rite
			add = pam_sway_to_rite_diocese_momentum_value
			scope:puppet_or_actor ?= { pam_is_clergy_ruler_trigger = yes }
			scope:recipient = { is_ruler = yes }
			pam_sway_to_rite_diocese_momentum_value > 0
			desc = PAM_SWAY_DIOCESE_MOMENTUM_REASON
		}
	}

	ai_targets = {
		ai_recipients = vassals
		ai_recipients = tributaries
		max = 10
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 120
		duchy = 24
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_will_do = {
		base = 25
		modifier = {
			scope:recipient.capital_county.clerical_region_title.holder ?= scope:puppet_or_actor
			add = 100
		}
		modifier = {
			scope:hook = yes
			add = 50
		}
		# Prefer option combinations that include a valid inducement
		modifier = {
			scope:pam_sway_endowment ?= yes
			add = 25
		}
		modifier = {
			scope:pam_sway_disputation ?= yes
			add = 25
		}
		modifier = {
			scope:pam_sway_pledge_favor ?= yes
			add = 25
		}
		modifier = {
			add = 50
			scope:puppet_or_actor = {
				has_trait = zealous
			}
		}
		modifier = {
			add = -50
			scope:puppet_or_actor = {
				has_trait = cynical
			}
		}
		modifier = {
			add = 10
			scope:recipient = {
				opinion = {
					target = scope:puppet_or_actor
					value >= 65
				}
			}
		}
		modifier = { # More likely to convert rulers that own a Holy Site
			add = 20
			pam_sway_recipient_holds_holy_site_trigger = yes
		}
		modifier = { # More likely to happen during Instability
			add = 15
			scope:puppet_or_actor.religion = religion:christianity_religion
			situation:the_christian_church ?= {
				has_situation_top_phase_parameter = the_christian_church_easier_sway_to_rite
			}
		}
		modifier = { # HoRs actually hustle
			add = 50
			scope:puppet_or_actor.rite.head_of_rite ?= scope:puppet_or_actor
		}
		modifier = { # More likely if the government is religious
			add = 50
			scope:puppet_or_actor = {
				government_is_religious_trigger = yes
			}
		}
		modifier = { # Heresiarchs are able to spread their rites easily
			add = 1000
			scope:puppet_or_actor = {
				OR = {
					has_trait = heresiarch
					has_trait = herald
				}
			}
		}
		modifier = { # Try to rigorously convert your heir so all efforts won't go to waste on succession
			add = 100
			scope:recipient = {
				is_primary_heir_of = scope:puppet_or_actor
			}
		}
		modifier = { # Much more likely to target vassals with neighboring counties with the swayed rite, instead of random ones
			add = 200
			scope:recipient = {
				is_vassal_of = scope:puppet_or_actor
				any_sub_realm_county = {
					any_neighboring_county = {
						this.rite = scope:puppet_or_actor.rite
					}
				}
			}
		}
		modifier = { # More likely against close family members
			add = 50
			scope:recipient = {
				is_close_family_of = scope:puppet_or_actor
			}
		}
		modifier = { # Prefer higher tiers
			add = scope:recipient.highest_held_title_tier
		}
		modifier = { # Much less likely If no counties in my realm have my rite, unless I'm zealous
			add = -150
			scope:puppet_or_actor = {
				any_realm_county = {
					this.rite = scope:puppet_or_actor.rite
					count = 0
				}
				NOT = { has_trait = zealous }
			}
		}
		modifier = { # Less likely for Mozarabic priests to try and convert all of Iberia's nobility
			add = -40
			scope:puppet_or_actor = {
				is_clergy = yes
				rite = rite:mozarabic_church
			}
			scope:recipient.rite = scope:recipient.faith.main_rite
		}
	}
}

# Clergy outreach: persuade rulers of your diocese, bordering realms, fellow prelates, or your liege to adopt your rite
sway_ruler_to_my_rite_interaction = {
	category = interaction_category_religion
	special_interaction = rite_conversion
	icon = icon_rite
	interface_priority = 45
	common_interaction = yes

	use_diplomatic_range = yes
	ai_maybe = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes
	notification_text = sway_ruler_to_my_rite_interaction_notification

	desc = sway_ruler_to_my_rite_interaction_desc

	is_shown = {
		scope:puppet_or_actor ?= {
			faith = scope:recipient.faith
			rite != scope:recipient.rite
			OR = {
				pam_is_clergy_ruler_trigger = yes
				faith.religious_head ?= this
			}
			trigger_if = {
				limit = {
					is_ai = yes
					NOT = { puppeteer ?= { is_ai = no } }
				}
				is_adult = yes
				is_incapable = no
			}
		}
		scope:puppet_or_actor != scope:recipient
		# Courtiers, subjects, and kin use the other sway variants, so we never show two against the same target
		scope:recipient = {
			NOR = {
				is_courtier_of = scope:puppet_or_actor
				target_is_liege_or_above = scope:puppet_or_actor
				is_tributary_of = scope:puppet_or_actor
			}
		}
		trigger_if = {
			limit = { scope:puppet_or_actor ?= { is_house_head = yes } }
			NOT = {
				pam_rite_sway_house_lane_trigger = {
					ACTOR = scope:puppet_or_actor
					RECIPIENT = scope:recipient
				}
			}
		}
	}

	cooldown_against_recipient = { years = 5 }

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			NOR = {
				is_at_war_with = scope:recipient
				has_trait = incapable
				is_adult = no
			}
			trigger_if = { # Only clergy are told why a target is out of reach; a Head of Faith reaches their whole faith
				limit = {
					pam_is_clergy_ruler_trigger = yes
					NOT = { faith.religious_head ?= this }
					#Also, Holy order leaders are not blocked by this when spreading their beliefs
					NAND = {
						scope:holy_order_leader ?= this
						exists = scope:order_tenet
					}
				}
				# One custom_tooltip lane per route inside the trigger, so the failure tooltip lists them all
				pam_rite_sway_clergy_reach_trigger = {
					ACTOR = scope:puppet_or_actor
					RECIPIENT = scope:recipient
				}
			}
		}
		scope:recipient = {
			NOR = {
				is_adult = no
				has_trait = incapable
				custom_tooltip = {
					text = sway_ruler_to_my_rite_interaction_hor_tt
					rite.head_of_rite ?= this
					NOT = { pam_sway_to_rite_head_of_faith_reclaims_trigger = { ACTOR = scope:puppet_or_actor } }
				}
				custom_tooltip = {
					text = sway_ruler_to_my_rite_interaction_hof_tt
					OR = {
						scope:puppet_or_actor.religious_head_or_challenger ?= this
						primary_title ?= { is_head_of_faith = yes }
					}
				}
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= pam_sway_ruler_to_my_rite_cost_value
			}
		}
	}

	cost = {
		piety = {
			value = pam_sway_ruler_to_my_rite_cost_value
			if = {
				limit = { scope:pam_sway_disputation ?= yes }
				add = medium_piety_value
			}
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	#Use hook
	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				has_usable_hook = scope:recipient
			}
			scope:recipient = {
				NOT = { is_imprisoned_by = scope:puppet_or_actor }
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	# Endow their church - paid to the recipient on acceptance
	send_option = {
		is_shown = {
			scope:puppet_or_actor ?= {
				pam_is_clergy_ruler_trigger = yes
				has_treasury = yes
			}
			scope:puppet_or_actor = scope:actor
			trigger_if = {
				limit = { scope:actor = { is_ai = yes } }
				scope:recipient = {
					OR = {
						is_ai = no
						any_held_title = { has_clerical_region = yes }
						highest_held_title_tier >= tier_kingdom
					}
				}
			}
		}
		is_valid = {
			scope:puppet_or_actor = {
				treasury >= pam_sway_to_rite_endowment_cost_value
			}
		}
		flag = pam_sway_endowment
		localization = PAM_SWAY_TO_RITE_ENDOWMENT_OPTION
	}
	# Theological disputation - unlocked by scholarly renown, costs extra piety
	send_option = {
		is_shown = {
			scope:puppet_or_actor ?= {
				pam_is_clergy_ruler_trigger = yes
			}
			scope:puppet_or_actor = scope:actor
		}
		is_valid = {
			custom_tooltip = {
				text = PAM_SWAY_TO_RITE_DISPUTATION_REQUIRES_SCHOLAR
				scope:puppet_or_actor = {
					has_trait = lifestyle_scholar
					has_trait_xp = {
						trait = lifestyle_scholar
						value >= 60
					}
				}
			}
			scope:puppet_or_actor = {
				piety >= pam_sway_to_rite_disputation_piety_total_value
			}
		}
		flag = pam_sway_disputation
		localization = PAM_SWAY_TO_RITE_DISPUTATION_OPTION
	}
	# Pledge a favor - only worth anything to a prelate who can call it in against our treasury
	send_option = {
		is_shown = {
			scope:puppet_or_actor ?= {
				pam_is_clergy_ruler_trigger = yes
				has_treasury = yes
			}
			scope:puppet_or_actor = scope:actor
			trigger_if = {
				limit = { scope:actor = { is_ai = yes } }
				scope:actor = { has_trait = trusting }
			}
		}
		is_valid = {
			scope:recipient = {
				can_add_hook = {
					target = scope:puppet_or_actor
					type = favor_hook
				}
			}
		}
		flag = pam_sway_pledge_favor
		localization = PAM_SWAY_TO_RITE_PLEDGE_FAVOR_OPTION
	}
	should_use_extra_icon = {
		scope:puppet_or_actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:puppet_or_actor
			object = scope:recipient
			scope:hook = yes
			scope:puppet_or_actor = { has_strong_hook = scope:recipient }
			NOT = { scope:recipient = { has_character_flag = ai_will_not_convert } }
		}
	}

	on_accept = {
		pam_sway_to_rite_on_accept_effect = yes
	}

	on_decline = {
		pam_sway_to_rite_on_decline_effect = yes
	}

	ai_accept = {
		base = -15

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:puppet_or_actor
			RECIPIENT = scope:recipient
		}

		religion_sway_to_rite_default_modifier = yes
		modifier = { # The Head of Faith calling them back to the mainline rite eases the Head of Rite refusal
			add = 100
			scope:recipient.rite.head_of_rite ?= scope:recipient
			pam_sway_to_rite_head_of_faith_reclaims_trigger = { ACTOR = scope:puppet_or_actor }
			desc = PAM_SWAY_HEAD_OF_FAITH_REASON
		}
		modifier = {
			desc = ASK_FOR_CONVERSION_RECIPIENT_WILL_NOT_ACCEPT
			add = -1500
			scope:recipient = {
				has_character_flag = ai_will_not_convert
			}
		}
		modifier = { # Endowing their church sweetens the petition
			add = 25
			scope:pam_sway_endowment ?= yes
			desc = PAM_SWAY_ENDOWMENT_REASON
		}
		modifier = { # Doubly so when our rite blesses such transactions
			add = 20
			scope:pam_sway_endowment ?= yes
			scope:puppet_or_actor = {
				OR = {
					rite = { rite_has_parameter = tenet_simony_ecclesiastical_purchase }
					has_personal_tenet_flag = tenet_simony_ecclesiastical_purchase
				}
			}
			desc = PAM_SWAY_ENDOWMENT_SIMONY_REASON
		}
		modifier = { # Hard to gainsay a doctor of scripture in open disputation
			add = {
				value = scope:puppet_or_actor.learning
				subtract = scope:recipient.learning
				multiply = 2
				min = 0
				add = 20
			}
			scope:pam_sway_disputation ?= yes
			desc = PAM_SWAY_DISPUTATION_REASON
		}
		modifier = { # They would hold a favor over us
			add = 30
			scope:pam_sway_pledge_favor ?= yes
			desc = PAM_SWAY_PLEDGE_FAVOR_REASON
		}
		modifier = { # Asking our own liege or above
			add = -80
			scope:puppet_or_actor ?= { pam_is_clergy_ruler_trigger = yes }
			scope:recipient = {
				is_liege_or_above_of = scope:puppet_or_actor
			}
			desc = PAM_SWAY_LIEGE_REASON
		}
		modifier = { # Prelate recipients resist; eases as their diocese converts to our rite
			add = {
				value = -75
				add = pam_sway_to_rite_diocese_momentum_value
			}
			scope:puppet_or_actor ?= { pam_is_clergy_ruler_trigger = yes }
			scope:recipient = {
				any_held_title = { has_clerical_region = yes }
			}
			desc = PAM_SWAY_RECIPIENT_PRELATE_REASON
		}
		modifier = { # Mirrors the diocese-adjacency rule the AI targeting always follows
			add = -60
			scope:puppet_or_actor ?= { pam_is_clergy_ruler_trigger = yes }
			scope:recipient = {
				any_held_title = { has_clerical_region = yes }
				NOR = {
					superior ?= scope:puppet_or_actor
					is_liege_or_above_of = scope:puppet_or_actor
					capital_county.clerical_region_title.holder ?= scope:puppet_or_actor
				}
			}
			NOT = {
				pam_rite_sway_adjacent_diocese_trigger = {
					ACTOR = scope:puppet_or_actor
					RECIPIENT = scope:recipient
				}
			}
			desc = PAM_SWAY_DISTANT_PRELATE_REASON
		}
		modifier = { # Independent recipient of higher rank
			add = -60
			scope:puppet_or_actor ?= { pam_is_clergy_ruler_trigger = yes }
			scope:recipient = {
				is_independent_ruler = yes
				government_is_religious_trigger = no
				highest_held_title_tier > scope:puppet_or_actor.highest_held_title_tier
				NOT = { is_liege_or_above_of = scope:puppet_or_actor }
			}
			desc = PAM_SWAY_INDEPENDENT_SECULAR_REASON
		}
		modifier = { # Actor's piety level
			add = {
				value = scope:puppet_or_actor.piety_level
				multiply = 5
			}
			scope:puppet_or_actor ?= {
				pam_is_clergy_ruler_trigger = yes
				piety_level >= 1
			}
			desc = PAM_SWAY_MY_PIETY_REASON
		}
		modifier = { # Their own diocese is already turning to our rite
			add = pam_sway_to_rite_diocese_momentum_value
			scope:puppet_or_actor ?= { pam_is_clergy_ruler_trigger = yes }
			scope:recipient = { is_ruler = yes }
			pam_sway_to_rite_diocese_momentum_value > 0
			desc = PAM_SWAY_DIOCESE_MOMENTUM_REASON
		}
		modifier = { # More likely for secular rulers to accept during instability
			add = 20
			situation:the_christian_church ?= {
				OR = {
					situation_participant_group:christian_regular_main_power_rulers = {
						participant_group_has_character = scope:recipient
						has_participant_group_parameter = the_christian_church_easier_sway_to_rite
					}
					situation_participant_group:christian_regular_secondary_powers_rulers = {
						participant_group_has_character = scope:recipient
						has_participant_group_parameter = the_christian_church_easier_sway_to_rite
					}
				}
			}
			desc = CHRISTIAN_CHURCH_PHASE_REASON
		}
		modifier = {
			add = 10
			desc = SWAY_TO_RITE_CATHEDRAL_STARTED_REASON
			scope:puppet_or_actor ?= {
				has_character_modifier = pam_grand_cathedral_started_modifier
			}
		}
		modifier = {
			add = 20
			desc = SWAY_TO_RITE_CATHEDRAL_COMPLETED_REASON
			scope:puppet_or_actor ?= {
				has_character_modifier = pam_grand_cathedral_completed_modifier
			}
		}
		modifier = {
			add = ecclesiastical_domicile_estate_easier_sway_to_rite_1
			desc = SWAY_TO_RITE_ESTATE_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_easier_sway_to_rite_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_estate_easier_sway_to_rite_2
			desc = SWAY_TO_RITE_ESTATE_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_easier_sway_to_rite_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_1
			desc = ESTATE_SWAY_CHAPTER_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_sway_chapter_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_2
			desc = ESTATE_SWAY_CHAPTER_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_sway_chapter_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_3
			desc = ESTATE_SWAY_CHAPTER_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_sway_chapter_3
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = puppets
	}

	ai_targets = {
		ai_recipients = rulers_in_clerical_region
		ai_recipients = subordinates
		max = 10
	}

	ai_targets = {
		# Peer prelates come from the situation roster; the ai_will_do gate trims them to adjacent dioceses
		ai_recipients = situation_participant_group
		parameter = the_christian_church
		max = 10
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 48
		duchy = 24
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_will_do = {
		base = 25
		modifier = {
			scope:recipient.capital_county.clerical_region_title.holder ?= scope:puppet_or_actor
			add = 100
		}
		modifier = {
			scope:hook = yes
			add = 50
		}
		# Prefer option combinations that include a valid inducement
		modifier = {
			scope:pam_sway_endowment ?= yes
			add = 25
		}
		modifier = {
			scope:pam_sway_disputation ?= yes
			add = 25
		}
		modifier = {
			scope:pam_sway_pledge_favor ?= yes
			add = 25
		}
		modifier = {
			add = 50
			scope:puppet_or_actor = {
				has_trait = zealous
			}
		}
		modifier = {
			add = -50
			scope:puppet_or_actor = {
				has_trait = cynical
			}
		}
		modifier = {
			add = 20
			scope:puppet_or_actor = {
				is_allied_to = scope:recipient
			}
		}
		modifier = {
			add = 10
			scope:puppet_or_actor = {
				has_relation_best_friend = scope:recipient
			}
		}
		modifier = {
			add = 10
			scope:recipient = {
				opinion = {
					target = scope:puppet_or_actor
					value >= 65
				}
			}
		}
		modifier = { # More likely to convert rulers that own a Holy Site
			add = 20
			pam_sway_recipient_holds_holy_site_trigger = yes
		}
		modifier = { # More likely to happen during Instability
			add = 15
			scope:puppet_or_actor.religion = religion:christianity_religion
			situation:the_christian_church ?= {
				has_situation_top_phase_parameter = the_christian_church_easier_sway_to_rite
			}
		}
		modifier = { # HoRs actually hustle
			add = 50
			scope:puppet_or_actor.rite.head_of_rite ?= scope:puppet_or_actor
		}
		modifier = { # AI restraint: stranger prelates are only valid targets while our dioceses touch
			add = -1000
			scope:recipient = {
				is_ruler = yes
				any_held_title = { has_clerical_region = yes }
				NOR = {
					superior ?= scope:puppet_or_actor
					is_liege_or_above_of = scope:puppet_or_actor
					capital_county.clerical_region_title.holder ?= scope:puppet_or_actor
				}
			}
			NAND = {
				scope:puppet_or_actor ?= {
					pam_is_archbishop_or_higher_trigger = yes
					piety_level >= high_piety_level
					# A landless recipient has no capital county to measure the distance to
					exists = scope:recipient.capital_county
					capital_county ?= {
						squared_distance = {
							target = scope:recipient.capital_county
							value <= squared_distance_large
						}
					}
				}
				pam_rite_sway_adjacent_diocese_trigger = {
					ACTOR = scope:puppet_or_actor
					RECIPIENT = scope:recipient
				}
			}
		}
		modifier = { # Push the rite into the neighboring diocese once our own is turning
			add = 150
			scope:recipient = {
				any_held_title = { has_clerical_region = yes }
			}
			scope:puppet_or_actor ?= {
				any_held_title = { has_clerical_region = yes }
			}
			pam_rite_sway_adjacent_diocese_trigger = {
				ACTOR = scope:puppet_or_actor
				RECIPIENT = scope:recipient
			}
		}
		modifier = { # More likely if the government is religious
			add = 50
			scope:puppet_or_actor = {
				government_is_religious_trigger = yes
			}
		}
		modifier = { # Heresiarchs are able to spread their rites easily
			add = 1000
			scope:puppet_or_actor = {
				OR = {
					has_trait = heresiarch
					has_trait = herald
				}
			}
		}
		modifier = { # More likely against close family members
			add = 50
			scope:recipient = {
				is_close_family_of = scope:puppet_or_actor
			}
		}
		modifier = { # Prefer higher tiers
			add = scope:recipient.highest_held_title_tier
		}
		modifier = { # Much less likely If no counties in my realm have my rite, unless I'm zealous
			add = -150
			scope:puppet_or_actor = {
				any_realm_county = {
					this.rite = scope:puppet_or_actor.rite
					count = 0
				}
				NOT = { has_trait = zealous }
			}
		}
		modifier = { # Less likely for Mozarabic priests to try and convert all of Iberia's nobility
			add = -40
			scope:puppet_or_actor = {
				is_clergy = yes
				rite = rite:mozarabic_church
			}
			scope:recipient.rite = scope:recipient.faith.main_rite
		}
	}
}

# interaction sent when reforming a faith
convert_on_reform_interaction = {
	category = interaction_category_religion
	special_interaction = reform_faith
	icon = icon_rite
	hidden = yes

	ai_maybe = no
	popup_on_receive = yes
	notification_text = sway_ruler_to_my_rite_interaction_notification

	desc = sway_ruler_to_my_rite_interaction_desc

	# Every adherent of the old faith receives this on reform, and anyone failing is_shown is skipped
	is_shown = {
		scope:actor.faith != scope:recipient.faith
	}

	cooldown_against_recipient = { years = 5 }

	on_accept = {
		scope:recipient = {
			set_character_rite = scope:actor.rite
		}
	}

	on_decline = {
		pam_sway_to_rite_on_decline_effect = yes
	}

	ai_accept = {
		base = 50

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:puppet_or_actor
			RECIPIENT = scope:recipient
		}

		religion_sway_to_rite_default_modifier = yes

		modifier = {
			desc = ASK_FOR_CONVERSION_REALM_REFORMATION_BONUS
			add = 500
			scope:recipient = {
				OR = {
					target_is_liege_or_above = scope:puppet_or_actor
					AND = {
						exists = superior
						superior = scope:puppet_or_actor
					}
				}
			}
		}

		modifier = {
			desc = ASK_FOR_CONVERSION_RECIPIENT_WILL_NOT_ACCEPT
			add = -1500
			scope:recipient = {
				has_character_flag = ai_will_not_convert
			}
		}
	}
}


# Sway Schism Stance - convince another Christian Church participant to adopt your schism stance
pam_sway_schism_stance_interaction = {
	category = interaction_category_religion
	icon = religious
	interface_priority = 44

	use_diplomatic_range = yes
	ai_maybe = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5

	desc = pam_sway_schism_stance_interaction_desc

	is_shown = {
		NOT = { has_global_variable = pam_great_schism_decision_taken }
		scope:actor = {
			pam_can_pick_great_schism_stance_trigger = yes
		}
		scope:recipient = {
			exists = top_participant_group:the_christian_church
			faith.religion ?= religion:christianity_religion
			is_ruler = yes
			is_ai = yes
		}
	}

	cooldown_against_recipient = { years = 2 }

	is_valid_showing_failures_only = {
		scope:actor = {
			NOR = {
				is_at_war_with = scope:recipient
				has_trait = incapable
				is_adult = no
			}
			custom_tooltip = {
				text = pam_sway_schism_stance_no_stance_tt
				has_variable = pam_schism_stance
			}
		}
		scope:recipient = {
			NOR = {
				is_adult = no
				has_trait = incapable
			}
			trigger_if = {
				limit = { scope:actor = { has_variable = pam_schism_stance } }
				custom_tooltip = {
					text = pam_sway_schism_stance_already_aligned_tt
					NOT = { var:pam_schism_stance ?= scope:actor.var:pam_schism_stance }
				}
			}
		}
	}

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = pam_sway_schism_stance_interaction_toast
				left_icon = scope:actor
				right_icon = scope:recipient
				scope:recipient = {
					if = {
						limit = { scope:actor.var:pam_schism_stance ?= flag:mainline }
						custom_tooltip = pam_sway_schism_stance_mainline_tt
					}
					else_if = {
						limit = { scope:actor.var:pam_schism_stance ?= flag:competitor }
						custom_tooltip = pam_sway_schism_stance_competitor_tt
					}
					else = {
						custom_tooltip = pam_sway_schism_stance_no_schism_tt
					}
					set_variable = {
						name = pam_schism_stance
						value = scope:actor.var:pam_schism_stance
					}
					add_opinion = {
						target = scope:actor
						modifier = pious_opinion
						opinion = 10
					}
				}
			}
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = pam_sway_schism_stance_interaction_decline_toast
				right_icon = scope:recipient
				scope:recipient = {
					add_opinion = {
						target = scope:actor
						modifier = annoyed_opinion
						opinion = -10
					}
				}
			}
		}
	}

	ai_accept = {
		base = -10
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1.0
			desc = AI_OPINION_REASON
		}
		modifier = { # Proposed stance favors the recipient's own rite
			add = 50
			desc = pam_sway_schism_stance_aligned_reason
			OR = {
				AND = {
					scope:actor.var:pam_schism_stance ?= flag:mainline
					scope:recipient.rite = faith:christian_faith.main_rite
				}
				AND = {
					scope:actor.var:pam_schism_stance ?= flag:competitor
					NOT = { scope:recipient.rite = faith:christian_faith.main_rite }
				}
			}
		}
		modifier = { # Proposed stance turns the recipient against their own rite
			add = -50
			desc = pam_sway_schism_stance_opposed_reason
			OR = {
				AND = {
					scope:actor.var:pam_schism_stance ?= flag:mainline
					NOT = { scope:recipient.rite = faith:christian_faith.main_rite }
				}
				AND = {
					scope:actor.var:pam_schism_stance ?= flag:competitor
					scope:recipient.rite = faith:christian_faith.main_rite
				}
			}
		}
		modifier = { # Heads of Faith or Rite are much harder to sway
			add = -50
			desc = pam_sway_schism_stance_religious_head_reason
			scope:recipient = {
				OR = {
					religious_head_or_challenger ?= this
					rite.head_of_rite ?= this
				}
			}
		}
		modifier = { # Recipient's personal tenets belong to the rite the actor's stance champions
			add = 20
			desc = pam_sway_schism_stance_tenet_aligned_reason
			OR = {
				AND = {
					scope:actor = { pam_schism_stance_supports_rite_trigger = { RITE = byzantine_rite OTHER_RITE = roman_rite } }
					scope:recipient = { pam_has_personal_tenet_of_rite_trigger = { RITE = byzantine_rite } }
				}
				AND = {
					scope:actor = { pam_schism_stance_supports_rite_trigger = { RITE = roman_rite OTHER_RITE = byzantine_rite } }
					scope:recipient = { pam_has_personal_tenet_of_rite_trigger = { RITE = roman_rite } }
				}
			}
		}
		modifier = { # Recipient's personal tenets belong to a rite the actor's stance does not champion
			add = -20
			desc = pam_sway_schism_stance_tenet_opposed_reason
			OR = {
				AND = {
					scope:actor = { NOT = { pam_schism_stance_supports_rite_trigger = { RITE = byzantine_rite OTHER_RITE = roman_rite } } }
					scope:recipient = { pam_has_personal_tenet_of_rite_trigger = { RITE = byzantine_rite } }
				}
				AND = {
					scope:actor = { NOT = { pam_schism_stance_supports_rite_trigger = { RITE = roman_rite OTHER_RITE = byzantine_rite } } }
					scope:recipient = { pam_has_personal_tenet_of_rite_trigger = { RITE = roman_rite } }
				}
			}
		}
		modifier = { # Zealous recipients stand firm once they have a stance
			add = -20
			desc = pam_sway_schism_stance_zealous_reason
			scope:recipient = {
				has_trait = zealous
				has_variable = pam_schism_stance
			}
		}
		modifier = { # Cynical recipients treat doctrine as politics
			add = 10
			desc = pam_sway_schism_stance_cynical_reason
			scope:recipient = { has_trait = cynical }
		}
	}

	ai_potential = {
		has_variable = pam_schism_stance
		NOT = { has_global_variable = pam_great_schism_decision_taken }
		is_adult = yes
		is_incapable = no
	}

	ai_targets = {
		ai_recipients = vassals
		ai_recipients = peer_vassals
		ai_recipients = liege
		ai_recipients = neighboring_rulers
		ai_recipients = family
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency = 12

	ai_will_do = {
		base = 25
		modifier = {
			add = 50
			scope:actor = { has_trait = zealous }
		}
		modifier = {
			add = -25
			scope:actor = { has_trait = cynical }
		}
		modifier = { # Keep allies onside
			add = 20
			scope:actor = { is_allied_to = scope:recipient }
		}
		modifier = { # Prefer higher tiers
			add = scope:recipient.highest_held_title_tier
		}
	}
}

# Appoint Cardinal Interaction
appoint_cardinal_interaction = {
	category = interaction_category_religion
	icon = cardinal
	interface_priority = 45
	common_interaction = yes

	# The Head of Faith names cardinals across all of Christendom
	use_diplomatic_range = no
	ai_maybe = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes
	notification_text = appoint_cardinal_interaction_notification

	desc = appoint_cardinal_interaction_desc

	is_available = {
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			this != scope:recipient
			faith ?= { has_doctrine_parameter = has_clerical_electors }
			faith = scope:recipient.faith
			pam_leads_college_of_cardinals_trigger = yes
		}
		scope:recipient = {
			# is_clergy alone misses PAM's landed archbishops, whose organization does not match the faith's
			pam_is_investiture_clergy_trigger = yes
			pam_can_hold_cardinalate_trigger = yes
			pam_can_receive_cardinalate_trigger = yes
			pam_pope_is_head_of_faith_or_rite_trigger = yes
			NOT = { exists = clerical_elector_title } # already a cardinal
		}
	}

	cooldown_against_recipient = { years = 10 }

	is_valid_showing_failures_only = {
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= medium_piety_value
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				treasury >= minor_treasury_value
			}
		}
		custom_tooltip = {
			text = appoint_cardinal_interaction_max_cardinals_tt
			scope:puppet_or_actor.faith ?= {
				NOT = { any_clerical_elector_title = { count >= 70 } }
			}
		}
		scope:puppet_or_actor = {
			is_available_quick = {
				adult = yes
				incapable = no
				imprisoned = no
				hostage = no
			}
		}
		scope:recipient = {
			is_available_quick = {
				adult = yes
				incapable = no
				imprisoned = no
				hostage = no
			}
			NOR = {
				is_at_war_with = scope:puppet_or_actor
				has_trait = excommunicated
			}
		}
		custom_tooltip = {
			text = pam_interaction_clerical_gender_tt
			scope:puppet_or_actor.rite = { rite_has_allowed_gender_for_clergy = scope:recipient }
		}
	}

	cost = {
		treasury = {
			value = scope:actor.minor_treasury_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	auto_accept = {
		trigger_if = {
			limit = {
				scope:recipient = {
					is_ai = yes
				}
			}
			always =  yes
		}
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				if = {
					limit = { minor_treasury_value > 0 }
					remove_treasury = {
						value = minor_treasury_value
					}
				}
			}
		}
		scope:recipient = {
			custom_tooltip = {
				text = appoint_cardinal_interaction_accept_tt
				hidden_effect = {
					grant_cardinal_title_effect = { CARDINAL_COUNTY = capital_county }
				}
			}
		}
		scope:puppet_or_actor = {
			show_as_tooltip = { add_piety = medium_piety_gain }
			hidden_effect = {
				send_interface_toast = {
					type = event_toast_effect_good
					title = appoint_cardinal_interaction_toast
					left_icon = scope:recipient
					right_icon = scope:cardinalate
					custom_tooltip = appoint_cardinal_interaction_accept_title_tt
					add_piety = medium_piety_value
				}
			}
			if = {
				limit = {
					scope:recipient = { pam_is_monastic_order_member_trigger = yes }
				}
				if = {
					limit = {
						can_add_hook = {
							target = scope:recipient
							type = favor_hook
						}
					}
					add_hook = {
						type = favor_hook
						target = scope:recipient
					}
				}
				pam_the_christian_church_appointed_cardinal_catalyst_effect = {
					POPE = scope:puppet_or_actor
					CARDINAL = scope:recipient
					OTHERWISE = catalyst_the_christian_church_appointed_monastic_cardinal
				}
			}
			else = {
				pam_the_christian_church_appointed_cardinal_catalyst_effect = {
					POPE = scope:puppet_or_actor
					CARDINAL = scope:recipient
					OTHERWISE = catalyst_the_christian_church_appointed_cardinal
				}
			}
		}
		if = {
			limit = {
				scope:is_puppet_action ?= yes
				scope:actor != scope:recipient
			}
			scope:actor = {
				send_interface_toast = {
					type = event_toast_effect_good
					title = appoint_cardinal_interaction_toast_puppeteer
					left_icon = scope:puppet_or_actor
					right_icon = scope:recipient
					custom_tooltip = appoint_cardinal_interaction_accept_title_tt
				}
			}
		}
	}

	on_decline = {
		scope:puppet_or_actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = appoint_cardinal_interaction_decline_toast
				right_icon = scope:recipient
				scope:recipient = {
					if = {
						limit = { is_ai = yes }
						add_opinion = {
							target = scope:puppet_or_actor
							modifier = annoyed_opinion
							opinion = -10
						}
					}
				}
			}
		}
		if = {
			limit = {
				scope:is_puppet_action ?= yes
				scope:actor != scope:recipient
			}
			scope:actor = {
				send_interface_toast = {
					type = event_toast_effect_bad
					title = appoint_cardinal_interaction_decline_toast_puppeteer
					left_icon = scope:puppet_or_actor
					right_icon = scope:recipient
				}
			}
		}
	}

	ai_accept = {
		base = 100
	}
	
	ai_targets = {
		ai_recipients = family
		max = 5
	}
	
	ai_targets = {
		ai_recipients = vassals
		ai_recipients = clerical_region_rulers_in_realm
		ai_recipients = rulers_in_clerical_region
		ai_recipients = subordinates
		ai_recipients = scripted_relations
		ai_recipients = faith_holy_order_leaders
	}
	
	ai_targets = {
		ai_recipients = courtiers
		max = 5
	}
	
	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 24
		kingdom = 6
		empire = 6
		hegemony = 6
	}

	ai_will_do = {
		base = 20
		modifier = { #The pope definitely wants to keep family close
			scope:puppet_or_actor = {
				is_any_family_relation_or_spouse_trigger = { CHARACTER = scope:recipient }
			}
			add = 70
		}
		modifier = {
			add = 10
			scope:recipient = {
				has_trait = overseer
			}
		}
		modifier = {
			add = 10
			scope:recipient = {
				has_trait = administrator
			}
		}
		modifier = {
			add = 30
			scope:recipient = {
				has_trait = zealous
			}
		}
		modifier = {
			add = 30
			scope:puppet_or_actor = {
				has_trait = zealous
			}
		}
		modifier = { # A cynical Pope still builds a College, just a venal one
			add = -20
			scope:puppet_or_actor = {
				has_trait = cynical
			}
		}
		modifier = {
			add = 20
			scope:puppet_or_actor = {
				is_allied_to = scope:recipient
			}
		}
		modifier = {
			add = 1000
			scope:puppet_or_actor = {
				has_relation_friend = scope:recipient
			}
		}
		modifier = {
			add = 1000
			scope:puppet_or_actor = {
				has_relation_lover = scope:recipient
			}
		}
		modifier = {
			add = 10
			scope:recipient = {
				opinion = {
					target = scope:puppet_or_actor
					value >= 65
				}
			}
		}
		modifier = { # More likely to seek out bishops who own a Holy Site
			add = 20
			scope:puppet_or_actor.faith = {
				any_holy_site = {
					holy_site_county ?= {
						holder ?= {
							OR = {
								this = scope:recipient
								is_vassal_or_below_of = scope:recipient
							}
						}
					}
				}
			}
		}
		modifier = {
			add = 150
			desc = pam_the_christian_church_desire_more_cardinals_desc
			scope:puppet_or_actor.religion = religion:christianity_religion
			situation:the_christian_church ?= {
				has_situation_top_phase_parameter = the_christian_church_desire_more_cardinals
			}
			scope:puppet_or_actor.faith ?= {
				any_clerical_elector_title = { count < 40 }
			}
		}
		modifier = { # HoR is a good candidate so that they're more controllable by the Pope.
			add = 50
			scope:recipient.rite.head_of_rite ?= scope:recipient
		}
		modifier = { # Traits in common
			add = 25
			scope:puppet_or_actor = {
				number_of_personality_traits_in_common = {
					target = scope:recipient
					value = 1
				}
			}
		}
		modifier = { # Traits in common
			add = 25
			scope:puppet_or_actor = {
				number_of_personality_traits_in_common = {
					target = scope:recipient
					value = 2
				}
			}
		}
		modifier = { # Traits in common
			add = 25
			scope:puppet_or_actor = {
				number_of_personality_traits_in_common = {
					target = scope:recipient
					value = 3
				}
			}
		}
		modifier = { # Same culture
			add = 40
			scope:puppet_or_actor = {
				has_same_culture_as = scope:recipient
			}
		}
		modifier = { # More likely to take this if we're running low on cardinals
			add = 100
			scope:puppet_or_actor.faith ?= {
				any_clerical_elector_title = { count < 20 }
			}
		}
		modifier = { # Much more likely to take this if we're running _very_ low
			add = 200
			scope:puppet_or_actor.faith ?= {
				any_clerical_elector_title = { count < 10 }
			}
		}
		modifier = { # Mitre and Crosier dynasty legacy
			add = 40
			scope:recipient = {
				dynasty ?= { has_dynasty_perk = pam_legacy_4 }
			}
		}
		modifier = {
			factor = 0
			scope:recipient = {
				has_relation_rival = scope:puppet_or_actor
			}
		}
		modifier = {
			factor = 0.5
			scope:puppet_or_actor.treasury < 500
			scope:puppet_or_actor.faith ?= {
				any_clerical_elector_title = { count >= 30 }
			}
		}
		modifier = {
			factor = 0.5
			scope:puppet_or_actor.faith ?= {
				any_clerical_elector_title = { count >= 30 }
			}
		}
		modifier = {
			factor = 0.5
			scope:puppet_or_actor.faith ?= {
				any_clerical_elector_title = { count >= 40 }
			}
		}
		modifier = {
			factor = 0
			scope:recipient = {
				pam_ai_cardinal_candidate_is_immersive_trigger = no
			}
		}
		# Players request their courtiers' cardinalates themselves
		modifier = {
			factor = 0
			scope:recipient = {
				is_ruler = no
				employer ?= {
					is_ai = no
					this != scope:puppet_or_actor
				}
			}
		}
	}
}
# Request Court Chaplain Cardinalate Interaction
request_court_chaplain_cardinalate_interaction = {
	category = interaction_category_religion
	icon = cardinal
	interface_priority = 45
	common_interaction = yes

	ai_maybe = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes
	notification_text = request_court_chaplain_cardinalate_interaction_notification

	desc = request_court_chaplain_cardinalate_interaction_desc

	cooldown_against_recipient = { years = 10 }

	# Actor-only tests belong here, since is_available runs once per actor and is_shown per recipient
	is_available = {
		pam_can_hold_cardinalate_trigger = yes
		NOT = { religious_head_or_challenger ?= this }
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = { pam_can_receive_cardinalate_trigger = yes }
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:actor != scope:recipient
		OR = {
			scope:actor.religious_head_or_challenger ?= scope:recipient
			AND = {
				NOT = { exists = scope:actor.faith.religious_head }
				scope:actor.faith = scope:recipient.faith
				scope:recipient = { pam_leads_college_of_cardinals_trigger = yes }
			}
		}
	}

	is_valid_showing_failures_only = {
		custom_tooltip = {
			text = appoint_cardinal_interaction_max_cardinals_tt
			scope:actor.faith ?= {
				NOT = { any_clerical_elector_title = { count >= 70 } }
			}
		}
		pam_not_antipope_when_recipient_is_hof_tt = { CHARACTER = scope:actor }
		scope:actor = {
			NOT = { has_trait = excommunicated }
			NOT = { is_at_war_with = scope:recipient }
			custom_tooltip = {
				text = actor_promised_pilgrimage_tt
				NOT = { has_character_modifier = promised_pilgrimage_to_clergy_modifier }
			}
			clergy_interaction_generic_piety_level_or_puppet_req_trigger = yes
			cp:councillor_court_chaplain ?= {
				is_available_quick = {
					adult = yes
					incapable = no
					imprisoned = no
					hostage = no
				}
				custom_tooltip = {
					text = request_court_chaplain_cardinalate_chaplain_not_excommunicated_tt
					NOT = { has_trait = excommunicated }
				}
				custom_tooltip = {
					text = request_court_chaplain_cardinalate_chaplain_not_cardinal_tt
					NOT = { exists = clerical_elector_title }
				}
				custom_tooltip = {
					text = request_court_chaplain_cardinalate_chaplain_follows_pope_tt
					pam_pope_is_head_of_faith_or_rite_trigger = yes
				}
			}
		}
		scope:recipient = {
			is_available_quick = {
				adult = yes
				incapable = no
				imprisoned = no
				hostage = no
			}
		}
	}

	is_highlighted = {
		scope:actor.piety_level > scope:recipient.piety_level
	}

	cost = {
		piety = pam_request_court_chaplain_cardinalate_cost_value
	}

	#Use hook
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
			scope:recipient = {
				NOT = { is_imprisoned_by = scope:actor }
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	send_option = {
		is_shown = {
			pam_offer_pilgrimage_option_shown_trigger = { ACTOR = scope:actor }
		}
		is_valid = {
			pam_offer_pilgrimage_option_valid_trigger = { ACTOR = scope:actor }
		}
		flag = offer_pilgrimage
		localization = OFFER_PILGRIMAGE_INTERACTION_OPTION
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
		}
	}

	on_accept = {
		scope:actor.cp:councillor_court_chaplain ?= {
			save_scope_as = new_cardinal
		}
		if = {
			limit = { exists = scope:new_cardinal }
			scope:actor = {
				send_interface_toast = {
					type = event_toast_effect_good
					title = request_court_chaplain_cardinalate_interaction_toast
					left_icon = scope:recipient
					right_icon = scope:new_cardinal
					custom_tooltip = {
						text = request_court_chaplain_cardinalate_interaction_accept_tt
						scope:new_cardinal = {
							grant_cardinal_title_effect = { CARDINAL_COUNTY = capital_county }
						}
					}
				}
			}
			if = {
				limit = { scope:new_cardinal = { is_ai = no } }
				scope:recipient = { save_scope_as = head_of_faith }
				scope:new_cardinal = { pam_notify_player_became_cardinal_effect = yes }
			}
			# on_lose_position covers other title gains
			if = {
				limit = {
					scope:actor = { NOT = { exists = puppet:external_theological_agent_puppet } }
				}
				custom_tooltip = {
					text = request_court_chaplain_cardinalate_becomes_clerical_puppet_tt
					scope:actor = { fire_councillor = scope:new_cardinal }
					scope:new_cardinal = {
						pam_make_clerical_ruler_puppet_effect = { PUPPETEER = scope:actor }
					}
				}
			}
			else = {
				custom_tooltip = {
					text = request_court_chaplain_cardinalate_leaves_council_tt
					scope:actor = { fire_councillor = scope:new_cardinal }
				}
			}
			scope:new_cardinal = {
				# The hat came from his liege's petition, and he knows whose it was
				add_opinion = {
					target = scope:actor
					modifier = grateful_opinion
					opinion = 50
				}
				# This is a promotion not a dismissal, so we hide the fired from council opinion or it cancels at once
				hidden_effect = {
					remove_opinion = {
						modifier = fired_from_council_opinion
						target = scope:actor
					}
				}
			}
		}
		pam_offer_pilgrimage_effect = {
			ACTOR = scope:actor
			CLERIC = scope:recipient
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = request_court_chaplain_cardinalate_interaction_decline_toast
				right_icon = scope:recipient
				if = {
					limit = { is_ai = yes }
					add_opinion = {
						target = scope:recipient
						modifier = annoyed_opinion
						opinion = -10
					}
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = head_of_faith
	}

	# Only kings and above bother the Pope with this
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 24
		empire = 24
		hegemony = 24
	}

	ai_will_do = {
		base = 30

		modifier = { # A kinsman in the College is a kinsman on the papal throne
			add = 60
			scope:actor.cp:councillor_court_chaplain ?= {
				is_any_family_relation_or_spouse_trigger = { CHARACTER = scope:actor }
			}
		}
		modifier = {
			add = 40
			scope:actor.cp:councillor_court_chaplain ?= {
				dynasty ?= scope:actor.dynasty
			}
		}
		modifier = { # No point elevating a chaplain we cannot steer
			add = 40
			scope:actor = {
				puppet:theological_agent_puppet ?= cp:councillor_court_chaplain
			}
		}
		modifier = {
			add = 30
			scope:actor = { has_trait = zealous }
		}
		modifier = {
			add = -60
			scope:actor = { has_trait = cynical }
		}
		modifier = { # A chaplain nobody respects will not be made a Cardinal
			add = -40
			scope:actor.cp:councillor_court_chaplain ?= {
				piety_level < 2
			}
		}
		modifier = { # No use spending the favour on a chaplain we are about to replace
			add = -50
			scope:actor = {
				exists = cp:councillor_court_chaplain
				opinion = {
					target = cp:councillor_court_chaplain
					value < 0
				}
			}
		}
		modifier = {
			factor = 0
			scope:actor.cp:councillor_court_chaplain ?= {
				pam_ai_cardinal_candidate_is_immersive_trigger = no
			}
		}
	}

	ai_accept = {
		base = 0

		# The petitioner's own standing with the Pope, shared with the other clerical title petitions
		clerical_petition_to_authority_acceptance_modifier = yes

		# Weak hook: a strong one already auto-accepts
		modifier = {
			scope:hook = yes
			add = 100
			scope:actor = { NOT = { has_strong_hook = scope:recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}

		modifier = {
			add = pam_offer_pilgrimage_acceptance_value
			scope:offer_pilgrimage = yes
			desc = OFFER_PILGRIMAGE_INTERACTION_OPTION_REASON
		}

		# The rest weighs the candidate rather than the petitioner
		opinion_modifier = {
			trigger = { exists = scope:actor.cp:councillor_court_chaplain }
			who = scope:recipient
			opinion_target = scope:actor.cp:councillor_court_chaplain
			desc = AI_OPINION_REASON
		}

		modifier = {
			add = -25
			exists = scope:actor.cp:councillor_court_chaplain
			scope:actor.cp:councillor_court_chaplain.rite != scope:recipient.rite
			desc = COURT_CHAPLAIN_DIFFERENT_RITE
		}

		modifier = {
			add = -50
			exists = scope:actor.cp:councillor_court_chaplain
			scope:recipient.rite = {
				NOT = { rite_has_allowed_gender_for_clergy = scope:actor.cp:councillor_court_chaplain }
			}
			desc = COURT_CHAPLAIN_WRONG_CLERICAL_GENDER
		}

		modifier = {
			add = {
				add = 10
				multiply = scope:actor.cp:councillor_court_chaplain.num_virtuous_traits
			}
			exists = scope:actor.cp:councillor_court_chaplain
			scope:actor.cp:councillor_court_chaplain.num_virtuous_traits > 0
			desc = COURT_CHAPLAIN_VIRTUOUS
		}

		modifier = {
			add = {
				add = -10
				multiply = scope:actor.cp:councillor_court_chaplain.num_sinful_traits
			}
			exists = scope:actor.cp:councillor_court_chaplain
			scope:actor.cp:councillor_court_chaplain.num_sinful_traits > 0
			desc = COURT_CHAPLAIN_SINFUL
		}

		modifier = {
			add = 10
			exists = scope:actor.cp:councillor_court_chaplain
			scope:actor.cp:councillor_court_chaplain = { has_education_learning_trigger = yes }
			desc = COURT_CHAPLAIN_LEARNING_EDUCATION_REASON
		}

		modifier = {
			add = 15
			exists = scope:actor.cp:councillor_court_chaplain
			scope:actor.cp:councillor_court_chaplain = { has_trait = celibate }
			desc = COURT_CHAPLAIN_CELIBATE
		}

		modifier = {
			add = 15
			exists = scope:actor.cp:councillor_court_chaplain
			scope:actor.cp:councillor_court_chaplain = { has_trait = devoted }
			desc = COURT_CHAPLAIN_DEVOTED
		}

		# A chaplain of no standing is not Cardinal material
		modifier = {
			add = -25
			exists = scope:actor.cp:councillor_court_chaplain
			scope:actor.cp:councillor_court_chaplain = { piety_level = 0 }
			desc = COURT_CHAPLAIN_LOW_PIETY
		}

		# A College short on Cardinals needs bodies more than it needs leverage
		modifier = {
			add = 60
			scope:recipient.faith ?= {
				any_clerical_elector_title = { count < 20 }
			}
			desc = COLLEGE_OF_CARDINALS_UNDERMANNED_REASON
		}

		modifier = {
			add = 100
			scope:recipient.faith ?= {
				any_clerical_elector_title = { count < 10 }
			}
			desc = COLLEGE_OF_CARDINALS_SEVERELY_UNDERMANNED_REASON
		}
	}
}
# Destroy Cardinalate Interaction
destroy_cardinalate_interaction = {
	category = interaction_category_religion
	icon = cardinal
	interface_priority = 45

	desc = destroy_cardinalate_interaction_desc
	filter_tags = { papabile }

	auto_accept = { always = yes }
	cooldown_against_recipient = { years = 10 }

	is_available = {
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			this != scope:recipient
			rite ?= { rite_has_parameter = has_clerical_electors }
			pam_leads_college_of_cardinals_trigger = yes
			trigger_if = { # A shrinking College is a problem the AI should not create
				limit = {
					is_ai = yes
					NOT = { puppeteer ?= { is_ai = no } }
				}
				faith ?= {
					any_clerical_elector_title = { count > 30 }
				}
			}
		}
		exists = scope:recipient.clerical_elector_title
		scope:recipient = {
			is_ai = yes
			faith = scope:actor.faith
		}
	}

	is_valid_showing_failures_only = {
		custom_tooltip = {
			text = destroy_cardinalate_interaction_min_cardinals_tt
			scope:puppet_or_actor.faith ?= {
				any_clerical_elector_title = { count > 10 }
			}
		}
		scope:puppet_or_actor = {
			is_available_quick = {
				adult = yes
				incapable = no
				imprisoned = no
				hostage = no
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= medium_piety_value
			}
		}
	}

	cost = {
		piety = major_piety_value
	}

	on_accept = {
		scope:recipient.clerical_elector_title ?= { save_scope_as = cardinalate }
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = destroy_cardinalate_interaction_toast
				left_icon = scope:puppet_or_actor
				right_icon = scope:recipient
				custom_tooltip = destroy_cardinalate_interaction_accept_tt
				scope:recipient = {
					add_opinion = {
						target = scope:puppet_or_actor
						modifier = revoked_title
					}
					pam_destroy_cardinal_title_effect = { CARDINALATE = scope:cardinalate }
					faith = {
						every_clerical_elector_title = {
							custom = custom.every_clerical_elector_title
							limit = {
								holder != scope:recipient
							}
							holder = {
								add_opinion = {
									target = scope:puppet_or_actor
									modifier = removed_cardinalate
								}
							}
						}
					}
				}
				situation:the_christian_church ?= {
					situation_participant_group:christian_clerical_main_power_rulers = {
						every_situation_group_participant = {
							custom = custom.every_main_power_clerical_ruler
							limit = {
								NOR = {
									this = scope:actor
									this = scope:puppet_or_actor
									this = scope:recipient
									exists = clerical_elector_title
								}
							}
							add_opinion = {
								target = scope:puppet_or_actor
								modifier = removed_cardinalate
								opinion = -20
							}
						}
					}
				}
				# Catalysts
				if = {
					limit = {
						scope:puppet_or_actor.religion = religion:christianity_religion
						situation:the_christian_church ?= { situation_top_has_catalyst = catalyst_the_christian_church_stripped_cardinalate }
					}
					situation:the_christian_church = { trigger_situation_catalyst = catalyst_the_christian_church_stripped_cardinalate }
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = subordinates
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	# Stripping a hat is a last resort, so nothing but a real grievance moves this off zero
	ai_will_do = {
		base = 0

		modifier = { # An excommunicate has no business choosing the next Head of Faith
			add = 100
			scope:recipient = { has_trait = excommunicated }
		}
		modifier = {
			add = 30
			scope:puppet_or_actor = {
				OR = {
					has_relation_rival = scope:recipient
					has_relation_nemesis = scope:recipient
				}
			}
		}
		modifier = { # Never against our own
			factor = 0
			scope:puppet_or_actor = {
				OR = {
					has_relation_friend = scope:recipient
					has_relation_best_friend = scope:recipient
					is_any_family_relation_or_spouse_trigger = { CHARACTER = scope:recipient }
				}
			}
		}
	}
}
# Give Cardinal Order Interaction
give_cardinal_order_interaction = {
	category = interaction_category_religion
	icon = icon_scheme_challenge_status
	interface_priority = 60
	desc = give_cardinal_order_interaction_desc

	common_interaction = yes
	filter_tags = { papabile }

	use_diplomatic_range = {
		scope:puppet_or_actor = { pam_leads_college_of_cardinals_trigger = no }
	}
	ai_maybe = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes

	auto_accept = {
		scope:recipient = { is_ai = no }
	}
	cooldown_against_recipient = { years = 10 }
	
	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			is_adult = yes
			is_incapable = no

		}
	}

	is_shown = {
		has_pam_dlc_trigger = yes
		scope:puppet_or_actor ?= {
			trigger_if = {
				limit = {
					scope:recipient.liege.puppet:theological_agent_puppet ?= scope:recipient
				}
			}
			trigger_else = {
				pam_leads_college_of_cardinals_trigger = yes
				#If they are a puppet of their liege the HoF cannot use this interaction
				NOT = {
					scope:recipient.liege.puppet:theological_agent_puppet ?= scope:recipient
				}
			}
			faith ?= scope:recipient.faith
		}
		#Check if they are a Cardinal
		exists = scope:recipient.clerical_elector_title
		scope:puppet_or_actor != scope:recipient
	}


	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			NOR = {
				is_at_war_with = scope:recipient
				has_trait = incapable
				is_adult = no
			}
		}
		scope:recipient = {
			NOR = {
				is_adult = no
				has_trait = incapable
				has_trait = excommunicated
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= minor_piety_value
			}
		}
	}

	cost = {
		piety = {
			value = {
				add = minor_piety_value
			}
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	send_option = { #Improve Development
		flag = cardinal_improve_development
		is_valid = {
			scope:recipient = {
				capital_county ?= {
					clerical_region_title ?= {
						custom_tooltip = {
							text = cardinal_order_improve_development_tt
							any_county_in_clerical_region = {
								faith = scope:recipient.faith
							}
						}
					}
				}
			}
		}
	}

	send_option = { #Convert Faith
		flag = cardinal_convert_faith
		is_valid = {
			scope:recipient = {
				capital_county ?= {
					clerical_region_title ?= {
						custom_tooltip = {
							text = cardinal_order_convert_faith_tt
							OR = {
								any_county_in_clerical_region = {
									pam_cardinal_order_convert_faith_in_region_county_trigger = { CARDINAL = scope:recipient }
								}
								any_county_in_clerical_region = {
									any_neighboring_county = {
										pam_cardinal_order_convert_faith_neighboring_county_trigger = { CARDINAL = scope:recipient }
									}
								}
							}
						}
					}
				}
			}
		}
	}

	send_option = { #Increase Control
		flag = cardinal_increase_control
		is_valid = {
			scope:recipient = {
				capital_county ?= {
					clerical_region_title ?= {
						custom_tooltip = {
							text = cardinal_order_increase_control_tt
							any_county_in_clerical_region = {
								faith = scope:recipient.faith
								county_control < 100
							}
						}
					}
				}
			}
		}
	}

	send_option = { #Accelerate Cultural Fascination
		flag = cardinal_accelerate_cultural_fascination
		is_valid = {
			custom_tooltip = {
				text = cardinal_order_accelerate_cultural_fascination_tt
				scope:puppet_or_actor ?= {
					culture.culture_head ?= {
						NOT = {
							has_character_modifier = pam_cardinal_order_accelerate_cultural_fascination_modifier
						}
					}
				}
			}
		}
	}

	send_option = { #Improve Plague Resistance
		flag = cardinal_improve_epidemic_resistance
		is_valid = {
			scope:recipient = {
				capital_county ?= {
					clerical_region_title ?= {
						custom_tooltip = {
							text = cardinal_order_improve_epidemic_resistance_tt
							any_county_in_clerical_region = {
								faith = scope:recipient.faith
								NOT = {
									has_county_modifier = pam_cardinal_order_improve_epidemic_resistance_modifier
								}
							}
						}
					}
				}
			}
		}
	}

	send_option = { #Improve Legitimacy
		flag = cardinal_improve_legitimacy
		is_valid = {
			scope:recipient = {
				capital_county ?= {
					clerical_region_title ?= {
						custom_tooltip = {
							text = cardinal_order_improve_legitimacy_tt
							any_county_in_clerical_region = {
								holder.top_liege = {
									has_legitimacy = yes
									NOT = {
										has_character_modifier = pam_cardinal_order_improve_legitimacy_modifier
									}
									faith = scope:recipient.faith
								}
							}
						}
					}
				}
			}
		}
	}

	send_option = { #Undermine Legitimacy
		flag = cardinal_undermine_legitimacy
		is_valid = {
			scope:recipient = {
				capital_county ?= {
					clerical_region_title ?= {
						custom_tooltip = {
							text = cardinal_order_undermine_legitimacy_tt
							any_county_in_clerical_region = {
								holder.top_liege = {
									has_legitimacy = yes
									NOT = {
										has_character_modifier = pam_cardinal_order_undermine_legitimacy_modifier
									}
									faith = scope:recipient.faith
								}
							}
						}
					}
				}
			}
		}
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				add_piety = { value = { add = minor_piety_value max = piety multiply = -1 } }
			}
		}
		scope:recipient = {
			if = {
				limit = { is_ai = yes }
				pam_choose_cardinal_order_switch_scripted_effect = yes
			}
			else = {
				trigger_event = { 
					id = pam_clergy_events.0010
					days = 10
				}
				show_as_tooltip = {
					pam_choose_cardinal_order_switch_scripted_effect = yes
				}
			}
		}
		if = {
			limit = {
				scope:recipient = { is_ai = yes }
				scope:actor = { is_ai = no }
			}
			pam_cardinal_order_accept_notify_players_effect = {
				HOF = scope:puppet_or_actor
			}
		}
	}

	on_decline = {
		scope:puppet_or_actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = give_cardinal_order_interaction_decline_toast
				left_icon = scope:puppet_or_actor
				right_icon = scope:recipient
				scope:recipient = {
					pam_cardinal_order_decline_effect = {
						HOF = scope:puppet_or_actor
						CARDINAL = scope:recipient
					}
				}
			}
		}
		if = {
			limit = {
				scope:is_puppet_action ?= yes
				scope:actor != scope:recipient
			}
			scope:actor = {
				send_interface_toast = {
					type = event_toast_effect_bad
					title = give_cardinal_order_interaction_decline_toast_puppeteer
					left_icon = scope:puppet_or_actor
					right_icon = scope:recipient
				}
			}
		}
	}

	ai_accept = {
		base = 25
		opinion_modifier = {
			opinion_target = scope:puppet_or_actor
			who = scope:recipient
			multiplier = 1
			desc = AI_OPINION_REASON
		}
		modifier = {
			add = 50
			scope:puppet_or_actor.rite = scope:recipient.rite
			desc = I_HAVE_THE_SAME_RITE
		}
		modifier = {
			add = 200
			scope:recipient.liege.puppet:theological_agent_puppet ?= scope:recipient
			desc = IS_YOUR_PUPPET
		}
		# is_shown already has the College relationship, so this skips the any_subordinate walk
		modifier = {
			add = 20
			scope:puppet_or_actor = { has_realm_law_flag = puppet_acceptance_1 }
			desc = CHURCH_AUTHORITY_1_REASON
		}
		modifier = {
			add = 30
			scope:puppet_or_actor = { has_realm_law_flag = puppet_acceptance_2 }
			desc = CHURCH_AUTHORITY_2_REASON
		}
		modifier = {
			add = 50
			scope:puppet_or_actor = { has_realm_law_flag = puppet_acceptance_3 }
			desc = CHURCH_AUTHORITY_3_REASON
		}
		modifier = {
			add = -20
			situation:the_christian_church ?= {
				has_situation_top_phase_parameter = era_type_crisis
			}
			desc = CHRISTIAN_CHURCH_PHASE_REASON
		}
		modifier = {
			add = 20
			situation:the_christian_church ?= {
				has_situation_top_phase_parameter = era_type_stable
			}
			desc = CHRISTIAN_CHURCH_PHASE_REASON
		}
	}
	ai_targets = {
		ai_recipients = subordinates
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 12
		empire = 1
		hegemony = 1
	}
	ai_will_do = {
		base = 50

		modifier = { # Traits in common
			add = 25
			scope:puppet_or_actor = {
				number_of_personality_traits_in_common = {
					target = scope:recipient
					value = 1
				}
			}
		}

		modifier = { # Traits in common
			add = 25
			scope:puppet_or_actor = {
				number_of_personality_traits_in_common = {
					target = scope:recipient
					value = 2
				}
			}
		}

		modifier = { # Traits in common
			add = 25
			scope:puppet_or_actor = {
				number_of_personality_traits_in_common = {
					target = scope:recipient
					value = 3
				}
			}
		}

		modifier = { # I like them
			add = 25
			scope:puppet_or_actor = {
				opinion = {
					value >= medium_positive_opinion
					target = scope:recipient
				}
			}
		}

		modifier = { # Same rite
			factor = 2
			scope:puppet_or_actor.rite = scope:recipient.rite
		}
	}
}

#Request Legitimacy from the Church
request_legitimacy_interaction = {
	category = interaction_category_religion
	icon = icon_clergy_request_legitimacy
	interface_priority = 100
	notification_text = request_legitimacy_interaction_notification
	greeting = positive
	common_interaction = yes

	use_diplomatic_range = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes

	desc = request_legitimacy_interaction_desc

	is_available = {
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			has_legitimacy = yes
			#Has theocratic head of faith or theocratic clergy
			pam_clergy_interactions_faith_trigger = yes
			NOT = {
				government_has_flag = government_is_ecclesiastical
			}
			is_ruler = yes
		}
		scope:puppet_or_actor ?= {
			has_legitimacy = yes
			NOT = {
				is_at_war_with = scope:recipient
			}
		}
		scope:recipient = {
			pam_request_legitimacy_priest_trigger = { CHARACTER = scope:puppet_or_actor }
			#AI should only bother player recipients if they're similar tier
			trigger_if = {
				limit = {
					scope:puppet_or_actor ?= { is_ai = yes }
					scope:recipient = { is_ai = no }
				}
				OR = {
					scope:puppet_or_actor ?= { highest_held_title_tier >= scope:recipient.highest_held_title_tier }
					scope:puppet_or_actor ?= { is_vassal_of = prev }
					is_allied_to = scope:puppet_or_actor
				}
			}
			NOT = { this = scope:actor }
		}
		pam_should_bother_clergy_interaction_trigger = { PRIEST = scope:recipient }
		# Those under an antipope ask them instead of the real Head of Faith
		trigger_if = {
			limit = {
				scope:recipient ?= scope:puppet_or_actor.faith.religious_head
			}
			scope:puppet_or_actor ?= { is_following_religious_head_challenger = no }
		}
	}

	is_highlighted = {
		scope:puppet_or_actor = {
			trigger_if = {
				limit = {
					highest_held_title_tier >= tier_duchy
				}
				legitimacy_level <= 1
			}
			trigger_else = {
				legitimacy_level = 0
			}
			is_character_interaction_potentially_accepted = {
				recipient = scope:recipient
				interaction = request_legitimacy_interaction
			}
		}
	}

	cooldown = { years = 10 }

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			clergy_interaction_generic_piety_level_or_puppet_req_trigger = yes
			pam_antipope_clerical_request_trigger = { RECIPIENT = scope:recipient }
		}
		scope:puppet_or_actor = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				activity = no
				travel = no
			}
			NOT = {
				has_trait = excommunicated
			}
		}
		scope:recipient = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
				adult = yes
			}
			NOT = {
				has_trait = excommunicated
			}
			highest_held_title_tier >= tier_duchy
			custom_tooltip = {
				text = relevant_theocrat_tt
				OR = {
					scope:puppet_or_actor.religious_head_or_challenger ?= scope:recipient
					scope:puppet_or_actor = {
						any_liege_or_above = {
							this = scope:recipient
						}
					}
					any_held_title = {
						has_clerical_region = yes
						any_county_in_clerical_region = {
							OR = {
								this = scope:puppet_or_actor.primary_title
								scope:puppet_or_actor.primary_title = {
									is_de_jure_liege_or_above_target = prev
								}
							}
						}
					}
					AND = {
						is_landed = yes
						any_held_title = {
							OR = {
								#they have a title beneath actor's titles
								any_this_title_or_de_jure_above = {
									holder ?= scope:puppet_or_actor
								}
								#they have a title that presides over actor's titles
								any_in_de_jure_hierarchy = {
									holder ?= scope:puppet_or_actor
								}
							}
						}
					}
				}
			}
		}
		custom_tooltip = {
			text = below_expected_legitimacy_tt
			scope:puppet_or_actor = {
				OR = {
					any_powerful_vassal = {
						is_ai = yes
						NOT = {
							scope:puppet_or_actor = {
								meets_legitimacy_expectation_of = prev
							}
						}
					}
					any_vassal = {
						is_ai = yes
						NOT = {
							scope:puppet_or_actor = {
								meets_legitimacy_expectation_of = prev
							}
						}
					}
				}
			}
		}
		pam_not_promised_pilgrimage_trigger = { ACTOR = scope:puppet_or_actor }
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= pam_request_legitimacy_cost_value
			}
		}
	}

	on_send = {

	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				if = {
					limit = { pam_request_legitimacy_cost_value > 0 }
					add_piety = {
						value = {
							add = pam_request_legitimacy_cost_value
							max = piety
							multiply = -1
						}
					}
				}
			}
		}
		scope:puppet_or_actor = {
			show_as_tooltip = {
				request_legitimacy_interaction_effect = yes
			}
			trigger_event = pam_interactions_events.0001
		}
	}

	on_decline = {
		if = {
			limit = {
				scope:recipient = {
					is_ai = no
				}
			}
			scope:puppet_or_actor = {
				add_opinion = {
					modifier = refusal_opinion
					target = scope:recipient
					opinion = -25
				}
				show_as_tooltip = {
					add_legitimacy = medium_legitimacy_loss
				}
			}
		}
		scope:puppet_or_actor = {
			trigger_event = pam_interactions_events.0002
		}
	}

	cost = {
		piety = {
			value = pam_request_legitimacy_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	auto_accept = {
		# Using a hook should make him auto accept
		custom_description = {
			text = "spending_hook"
			subject = scope:puppet_or_actor
			object = scope:recipient
			scope:use_hook = yes
			scope:puppet_or_actor = { has_strong_hook = scope:recipient }
		}
	}

	ai_accept = {
		base = 0

		modifier = { # By God Alone - Secular Faith: the petitioner holds the ear of the clergy
			add = 25
			desc = pam_sf_ear_of_clergy_accept_reason
			trigger = {
				scope:puppet_or_actor = { has_character_modifier = pam_sf_ear_of_clergy_modifier }
			}
		}

		#BIG BONUS FROM NEEDING LEGITIMACY
		modifier = {
			scope:puppet_or_actor = {
				OR = {
					AND = {
						legitimacy_level = 0
						highest_held_title_tier >= tier_county
					}
					AND = {
						legitimacy_level = 1
						highest_held_title_tier >= tier_duchy
					}
					AND = {
						legitimacy_level = 2
						highest_held_title_tier >= tier_kingdom
					}
					AND = {
						legitimacy_level = 3
						highest_held_title_tier >= tier_empire
					}
				}
			}
			add = 20
			desc = LOW_LEGITIMACY_REASON
		}
		modifier = {
			scope:puppet_or_actor = {
				legitimacy_level >= 4
			}
			add = -40
			desc = HIGH_LEGITIMACY_REASON
		}
		modifier = {
			scope:puppet_or_actor = {
				legitimacy_level = 0
				highest_held_title_tier >= tier_kingdom
			}
			add = 20
			desc = VERY_LOW_LEGITIMACY_REASON
		}
		#Your gender is scorned by their faith
		modifier = {
			OR = {
				AND = {
					scope:puppet_or_actor = {
						is_female = yes
					}
					scope:recipient = {
						is_female = no
						rite = {
							rite_has_parameter = male_dominated_law
						}
					}
				}
				AND = {
					scope:puppet_or_actor = {
						is_male = yes
					}
					scope:recipient = {
						is_male = no
						rite = {
							rite_has_parameter = female_dominated_law
						}
					}
				}
			}
			add = -60
			desc = NON_DOMINANT_GENDER_REASON
		}

		# Weak hook: extra points
		modifier = {
			scope:use_hook = yes
			add = 200
			scope:puppet_or_actor = { NOT = { has_strong_hook = scope:recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}

		general_secular_to_ecclesiastic_acceptance_modifier = yes

		#Interaction options
		modifier = {
			add = {
				value = 0
				scope:puppet_or_actor = {
					every_patroned_holy_order = {
						limit = {
							leader = {
								government_has_flag = government_is_monastic_holy_order
							}
						}
						add = 15
					}
				}
				max = 100
			}
			scope:monastic_support = yes
			desc = MONASTIC_SUPPORT_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 0
				scope:puppet_or_actor = {
					every_held_title = {
						limit = {
							tier = tier_county
							NOT = {
								any_county_province = {
									is_occupied = yes
								}
							}
							development_level >= 1
						}
						add = 10
						max = 60
					}
				}
			}
			scope:tithe = yes
			desc = RAISE_A_TITHE_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 20
				multiply = scope:puppet_or_actor.highest_held_title_tier
			}
			scope:offer_hook = yes
			desc = OFFER_HOOK_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 25
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:puppet_or_actor.major_gold_value < scope:recipient.minor_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 50
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:puppet_or_actor.major_gold_value < scope:recipient.major_gold_value
			scope:puppet_or_actor.major_gold_value >= scope:recipient.minor_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 75
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:puppet_or_actor.major_gold_value >= scope:recipient.major_gold_value
			scope:puppet_or_actor.major_gold_value < scope:recipient.monumental_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 100
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:puppet_or_actor.major_gold_value >= scope:recipient.monumental_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = pam_offer_pilgrimage_acceptance_value
			scope:offer_pilgrimage = yes
			desc = OFFER_PILGRIMAGE_INTERACTION_OPTION_REASON
		}

		#Christian situation
		modifier = {
			situation:the_christian_church ?= {
				any_participant_group = { # Both characters are involved in the situation
					any_situation_group_participant = {
						this = scope:puppet_or_actor
					}
					trigger_if = {
						limit = { scope:recipient = { is_ruler = yes } }
						any_situation_group_participant = {
							this = scope:recipient
						}
					}
				}
				has_situation_top_phase_parameter = preach_legitimacy_acceptance_bonus
			}
			add = 50
			desc = preach_legitimacy_acceptance_bonus_desc
		}
	}

	send_option = {
		is_shown = {
			scope:recipient != scope:puppet_or_actor
		}
		is_valid = {
			scope:puppet_or_actor = {
				has_usable_hook = scope:recipient
			}
			trigger_if = {
				limit = {
					scope:recipient = {
						is_ai = no
					}
				}
				scope:puppet_or_actor = { is_ai = no }
			}
		}
		flag = use_hook
		localization = EDUCATION_HOOK
	}

	send_option = {
		is_valid = {
			custom_tooltip = {
				text = patroned_low_worldliness_holy_order_tt
				scope:puppet_or_actor = {
					any_patroned_holy_order = {
						leader = {
							government_has_flag = government_is_monastic_holy_order
						}
					}
				}
			}
			trigger_if = {
				limit = {
					scope:puppet_or_actor = {
						is_ai = yes
					}
				}
				scope:puppet_or_actor = {
					short_term_gold >= major_gold_value
				}
			}
		}
		flag = monastic_support
		localization = MONASTIC_SUPPORT_INTERACTION_OPTION
	}

	send_option = {
		is_valid = {
			custom_tooltip = {
				text = tithable_counties_tt
				scope:puppet_or_actor = {
					any_held_title = {
						tier = tier_county
						NOT = {
							any_county_province = {
								is_occupied = yes
							}
						}
						development_level >= 1
					}
				}
			}
			trigger_if = {
				limit = {
					scope:puppet_or_actor = {
						is_ai = yes
					}
				}
				scope:puppet_or_actor = {
					NOR = {
						ai_has_economical_boom_personality = yes
						ai_has_pious_builder_personality = yes
					}
				}
			}
		}
		flag = tithe
		localization = RAISE_A_TITHE_INTERACTION_OPTION
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				trigger_if = {
					limit = {
						scope:puppet_or_actor = {
							is_ai = yes
						}
					}
					short_term_gold >= massive_gold_value
				}
				trigger_else = {
					gold >= medium_gold_value
				}
			}
		}
		flag = donate_faith
		localization = DONATE_TO_THE_FAITH_INTERACTION_OPTION
	}

	send_option = {
		is_valid = {
			NOT = {
				scope:recipient = {
					has_usable_hook = scope:puppet_or_actor
				}
			}
			scope:recipient = {
				can_add_hook = {
					target = scope:puppet_or_actor
					type = favor_hook
				}
			}
			trigger_if = {
				limit = {
					scope:puppet_or_actor = { is_ai = yes }
				}
				scope:puppet_or_actor = { legitimacy_level < 1 }
			}
		}
		flag = offer_hook
		localization = OFFER_HOOK_INTERACTION_OPTION
	}

	send_option = {
		is_shown = {
			pam_offer_pilgrimage_option_shown_trigger = { ACTOR = scope:puppet_or_actor }
		}
		is_valid = {
			pam_offer_pilgrimage_option_valid_trigger = { ACTOR = scope:puppet_or_actor }
		}
		flag = offer_pilgrimage
		localization = OFFER_PILGRIMAGE_INTERACTION_OPTION
	}

	should_use_extra_icon = {
		scope:puppet_or_actor = { has_usable_hook = scope:recipient }
	}

	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	ai_targets = {
		ai_recipients = head_of_faith
		ai_recipients = realm_priest_superior
		ai_recipients = realm_priest_top_superior
		ai_recipients = peer_vassals
		ai_recipients = vassals
		ai_recipients = councillors
		ai_recipients = liege
		ai_recipients = top_liege
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 48
		duchy = 24
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_will_do = {
		base = 10
		#Low legitimacy is the only really good reason to do this
		modifier = {
			scope:puppet_or_actor = {
				legitimacy_level = 0
			}
			add = 100
		}
		modifier = {
			scope:puppet_or_actor = {
				legitimacy_level = 1
				highest_held_title_tier >= tier_duchy
			}
			add = 75
		}
		modifier = {
			scope:puppet_or_actor = {
				legitimacy_level = 2
				highest_held_title_tier >= tier_kingdom
			}
			add = 50
		}
		modifier = {
			scope:puppet_or_actor = {
				legitimacy_level = 3
				highest_held_title_tier >= tier_empire
			}
			add = 50
		}
		modifier = {
			scope:puppet_or_actor = {
				rite = {
					has_tenet_status = {
						tenet = tenet_simony
						status = prohibited
					}
				}
			}
			add = -50
		}
		#Angering other faith counties matters a tiny bit
		modifier = {
			add = {
				value = 0
				scope:puppet_or_actor = {
					every_held_title = {
						limit = {
							tier = tier_county
							NOT = {
								faith = scope:puppet_or_actor.faith
							}
							rite = {
								rite_hostility_level = {
									target = scope:puppet_or_actor.rite
									value >= faith_astray_level
								}
							}
						}
						add = -5
					}
				}
			}
		}
		#Don't want to anger different faith powerful vassals
		modifier = {
			add = {
				value = 0
				scope:puppet_or_actor = {
					every_powerful_vassal = {
						limit = {
							NOR = {
								faith = scope:puppet_or_actor.faith
								has_dread_level_towards = {
									target = scope:puppet_or_actor
									level >= 1
								}
							}
							rite = {
								rite_hostility_level = {
									target = scope:puppet_or_actor.rite
									value >= faith_astray_level
								}
							}
						}
						add = -20
					}
				}
			}
		}
	}
}

#Strengthen my claim, powerful clergy guy
strengthen_claim_interaction = {
	category = interaction_category_religion
	icon = icon_clergy_request_pressed_claim
	interface_priority = 30
	target_type = title
	target_filter = claimed_titles
	target_source = puppet_or_actor
	notification_text = strengthen_claim_interaction_notification
	greeting = positive
	cooldown_against_recipient = { years = 10 }
	use_diplomatic_range = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes

	desc = strengthen_claim_interaction_desc

	is_available = {
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			#Has theocratic head of faith or
			pam_clergy_interactions_faith_trigger = yes
			is_ruler = yes
			NOT = {
				government_has_flag = government_is_ecclesiastical
			}
			any_claim = {
				pressed = no
			}
		}
		scope:puppet_or_actor ?= {
			has_legitimacy = yes
			NOT = {
				is_at_war_with = scope:recipient
			}
		}
		scope:recipient = {
			pam_request_legitimacy_priest_trigger = { CHARACTER = scope:puppet_or_actor }
			NOT = { this = scope:actor }
		}
		pam_should_bother_clergy_interaction_trigger = { PRIEST = scope:recipient }
		# Those under an antipope ask them instead of the real Head of Faith
		trigger_if = {
			limit = {
				scope:recipient ?= scope:puppet_or_actor.faith.religious_head
			}
			scope:puppet_or_actor ?= { is_following_religious_head_challenger = no }
		}
	}

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			clergy_interaction_generic_piety_level_or_puppet_req_trigger = yes
			pam_antipope_clerical_request_trigger = { RECIPIENT = scope:recipient }
			trigger_if = {
				limit = {
					highest_held_title_tier >= tier_kingdom
				}
				legitimacy_level >= 4
			}
			trigger_else = {
				legitimacy_level >= 3
			}
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
			}
			custom_tooltip = {
				text = above_expected_legitimacy_tt
				any_vassal = {
					count = all
					trigger_if = {
						limit = {
							is_ai = yes
						}
						scope:puppet_or_actor = {
							meets_legitimacy_expectation_of = prev
						}
					}
				}
			}
		}
		scope:recipient = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
				adult = yes
			}
			NOT = {
				has_trait = excommunicated
			}
			highest_held_title_tier >= tier_duchy
			custom_tooltip = {
				text = relevant_theocrat_tt
				OR = {
					scope:puppet_or_actor.religious_head_or_challenger ?= scope:recipient
					scope:puppet_or_actor = {
						any_liege_or_above = {
							this = scope:recipient
						}
					}
					any_held_title = {
						has_clerical_region = yes
						any_county_in_clerical_region = {
							OR = {
								this = scope:puppet_or_actor.primary_title
								scope:puppet_or_actor.primary_title = {
									is_de_jure_liege_or_above_target = prev
								}
							}
						}
					}
					AND = {
						is_landed = yes
						any_held_title = {
							OR = {
								#they have a title beneath actor's titles
								any_this_title_or_de_jure_above = {
									holder ?= scope:puppet_or_actor
								}
								#they have a title that presides over actor's titles
								any_in_de_jure_hierarchy = {
									holder ?= scope:puppet_or_actor
								}
							}
						}
					}
				}
			}
		}
		pam_not_promised_pilgrimage_trigger = { ACTOR = scope:puppet_or_actor }
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= pam_strengthen_claim_cost_value
			}
		}
	}
	can_be_picked_title = {
		custom_tooltip = {
			text = must_have_weak_claim_tt
			scope:target ?= { save_temporary_scope_as = claimed_temp }
			scope:puppet_or_actor = {
				any_claim = {
					pressed = no
					this = scope:claimed_temp
				}
			}
		}

		trigger_if = {
			limit = {
				NOT = {
					scope:puppet_or_actor.religious_head_or_challenger ?= scope:recipient
				}
			}
			custom_tooltip = {
				text = hof_high_claim_req_tt
				scope:target ?= {
					tier <= tier_duchy
				}
			}
		}
		#Try to avoid letting you steal the cleric's lands with this interaction... not simple though. I think this works
		trigger_if = {
			limit = {
				scope:puppet_or_actor = {
					NOT = { is_vassal_or_below_of = scope:recipient }
				}
			}
			# Is not held by recipient or a de jure title under recipient
			custom_tooltip = {
				text = claim_not_in_realm_of_recipient_tt
				scope:target = {
					NOR = {
						any_this_title_or_de_jure_above = {
							holder ?=  {
								OR = {
									this = scope:recipient
									any_liege_or_above = {
										this = scope:recipient
									}
								}
							}
						}
						#A title comparable to recipient, not above them
						AND = {
							tier <= scope:recipient.highest_held_title_tier
							any_de_jure_county = {
								holder ?= {
									OR = {
										this = scope:recipient
										any_liege_or_above = {
											this = scope:recipient
										}
									}
								}
							}
						}
					}
				}
			}
		}
		trigger_else = {
			# Is not held by recipient or a de jure title under recipient
			custom_tooltip = {
				text = claim_not_held_by_recipient_tt
				scope:target = {
					NOR = {
						holder ?= {
							this = scope:recipient
						}
						#A title comparable to recipient, not above them
						AND = {
							tier <= scope:recipient.highest_held_title_tier
							any_de_jure_county = {
								holder ?= {
									this = scope:recipient
								}
							}
						}
					}
				}
			}
		}

		#Is not for a title in recipient's realm

	}

	on_send = {

	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				if = {
					limit = { pam_strengthen_claim_cost_value > 0 }
					add_piety = {
						value = {
							add = pam_strengthen_claim_cost_value
							max = piety
							multiply = -1
						}
					}
				}
			}
		}
		scope:puppet_or_actor = {
			show_as_tooltip = {
				strengthen_claim_interaction_effect = yes
			}
			trigger_event = pam_interactions_events.0010
		}
	}

	on_decline = {
		if = {
			limit = {
				scope:recipient = {
					is_ai = no
				}
			}
			scope:puppet_or_actor = {
				add_opinion = {
					modifier = refusal_opinion
					target = scope:recipient
					opinion = {
						value = -15
						multiply = {
							value = scope:target.tier
							subtract = 1
						}
					}
				}
			}
			scope:target.holder ?= {
				add_opinion = {
					target = scope:recipient
					modifier = grateful_opinion
					opinion = {
						value = 10
						multiply = {
							value = scope:target.tier
							subtract = 1
						}
					}
				}
			}
		}
		scope:puppet_or_actor = {
			trigger_event = pam_interactions_events.0011
		}
	}

	cost = {
		piety = {
			value = pam_strengthen_claim_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	auto_accept = {
		# Using a hook should make him auto accept
		custom_description = {
			text = "spending_hook"
			subject = scope:puppet_or_actor
			object = scope:recipient
			scope:use_hook = yes
			scope:puppet_or_actor = { has_strong_hook = scope:recipient }
		}
	}

	ai_accept = {
		base = 0

		modifier = { # By God Alone - Secular Faith: the petitioner holds the ear of the clergy
			add = 25
			desc = pam_sf_ear_of_clergy_accept_reason
			trigger = {
				scope:puppet_or_actor = { has_character_modifier = pam_sf_ear_of_clergy_modifier }
			}
		}

		modifier = {
			scope:puppet_or_actor = {
				legitimacy_level >= 5
			}
			add = 20
			desc = HIGH_LEGITIMACY_REASON
		}
		#Your gender is scorned by their faith
		modifier = {
			OR = {
				AND = {
					scope:puppet_or_actor = {
						is_female = yes
					}
					scope:recipient = {
						is_female = no
						rite = {
							rite_has_parameter = male_dominated_law
						}
					}
				}
				AND = {
					scope:puppet_or_actor = {
						is_male = yes
					}
					scope:recipient = {
						is_male = no
						rite = {
							rite_has_parameter = female_dominated_law
						}
					}
				}
			}
			add = -20
			desc = NON_DOMINANT_GENDER_REASON
		}
		# Weak hook: extra points
		modifier = {
			scope:use_hook = yes
			add = 200
			scope:puppet_or_actor = { NOT = { has_strong_hook = scope:recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}

		#Acceptance modifiers for all these ask the clergy for stuff interactions
		general_secular_to_ecclesiastic_acceptance_modifier = yes

		#Acceptance modifiers related to clergy's relation to target title and its possible holders
		title_acquisition_clerical_acceptance_modifier = yes

		#Interaction options
		modifier = {
			add = {
				value = 20
				multiply = scope:puppet_or_actor.highest_held_title_tier
			}
			scope:offer_hook = yes
			desc = OFFER_HOOK_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 25
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:puppet_or_actor.medium_gold_value < scope:recipient.miniscule_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 50
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:puppet_or_actor.medium_gold_value < scope:recipient.medium_gold_value
			scope:puppet_or_actor.medium_gold_value >= scope:recipient.miniscule_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 75
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:puppet_or_actor.medium_gold_value >= scope:recipient.medium_gold_value
			scope:puppet_or_actor.medium_gold_value < scope:recipient.massive_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 100
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:puppet_or_actor.medium_gold_value >= scope:recipient.massive_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 10
				if = {
					limit = {
						scope:puppet_or_actor.highest_held_title_tier > scope:recipient.highest_held_title_tier
					}
					multiply = {
						value = scope:puppet_or_actor.highest_held_title_tier
						subtract = scope:recipient.highest_held_title_tier
						add = 1
					}
				}
				else_if = {
					limit = {
						scope:puppet_or_actor.highest_held_title_tier < scope:recipient.highest_held_title_tier_minus_one
					}
					multiply = 0.25
				}
				else_if = {
					limit = {
						scope:puppet_or_actor.highest_held_title_tier < scope:recipient.highest_held_title_tier
					}
					multiply = 0.5
				}
				if = {
					limit = {
						OR = {
							is_liege_or_above_of = scope:recipient
							liege ?= scope:recipient.liege
							capital_county.holder ?= {
								OR = {
									this = scope:puppet_or_actor
									any_liege_or_above = {
										this = scope:puppet_or_actor
									}
								}
							}
						}
					}
					multiply = 3
				}
				else_if = {
					limit = {
						scope:recipient = {
							OR = {
								any_neighboring_top_liege_realm_owner = {
									this = scope:puppet_or_actor
								}
								capital_county = {
									any_neighboring_county = {
										OR = {
											holder = scope:puppet_or_actor
											holder = {
												any_liege_or_above = {
													this = scope:puppet_or_actor
												}
											}
										}
									}
								}
							}
						}
					}
					multiply = 2
				}
			}
			scope:threaten_priest = yes
			desc = THREATEN_PRIEST_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = pam_offer_pilgrimage_acceptance_value
			scope:offer_pilgrimage = yes
			desc = OFFER_PILGRIMAGE_INTERACTION_OPTION_REASON
		}


		#Cleric hesitating because of comparison to target's holder
		modifier = {
			exists = scope:target.holder
			scope:recipient = { save_temporary_scope_as = cleric }
			scope:target.holder = { save_temporary_scope_as = owner }
			clerical_hesitation_from_target_holder_value != 0
			desc = RECIPIENTS_ESTIMATION_OF_TARGET_HOLDER_PIETY_REASON
			add = {
				value = clerical_hesitation_from_target_holder_value
				multiply = -20
			}
		}
		modifier = {
			scope:recipient = { save_temporary_scope_as = cleric }
			exists = scope:target.holder
			scope:target.holder = { save_temporary_scope_as = owner }
			scope:target.holder = { is_independent_ruler = no }
			scope:puppet_or_actor = { is_independent_ruler = no }
			scope:target.holder.top_liege ?= scope:puppet_or_actor.top_liege
			NOR = {
				scope:puppet_or_actor.liege = scope:target.holder.liege
				scope:target.holder.liege = scope:puppet_or_actor
				scope:puppet_or_actor.top_liege = scope:target.holder
			}
			clerical_hesitation_from_potential_defender_value != 0
			desc = RECIPIENTS_ESTIMATION_OF_TARGET_LIEGE_PIETY_REASON
			add = {
				value = clerical_hesitation_from_potential_defender_value
				multiply = -20
			}

		}
		modifier = {
			exists = scope:target.holder
			scope:recipient = { save_temporary_scope_as = cleric }
			scope:target.holder = { save_temporary_scope_as = owner }
			scope:target.holder = {
				is_independent_ruler = no
				NOT = {
					top_liege = scope:puppet_or_actor.top_liege
				}
			}
			clerical_hesitation_from_potential_defender_value != 0
			desc = RECIPIENTS_ESTIMATION_OF_TARGET_TOP_LIEGE_PIETY_REASON
			add = {
				value = clerical_hesitation_from_potential_defender_value
				multiply = -20
			}

		}
		modifier = {
			scope:recipient = { save_temporary_scope_as = cleric }
			trigger_if = {
				limit = {
					exists = scope:target.holder
				}
				scope:target.holder = {
					save_temporary_scope_as = owner
				}
			}
			scope:target = {
				de_jure_liege ?= {
					exists = holder
					NOR = {
						holder = scope:recipient
						holder = scope:puppet_or_actor
						holder = scope:target.holder
					}
				}
			}
			clerical_hesitation_from_potential_defender_value != 0
			desc = RECIPIENTS_ESTIMATION_OF_TARGET_DE_JURE_LIEGE_PIETY_REASON
			add = {
				value = clerical_hesitation_from_potential_defender_value
				multiply = -20
			}
		}

		#Christian situation
		modifier = {
			situation:the_christian_church ?= {
				any_participant_group = { # Both characters are involved in the situation
					any_situation_group_participant = {
						this = scope:puppet_or_actor
					}
					trigger_if = {
						limit = { scope:recipient = { is_ruler = yes } }
						any_situation_group_participant = {
							this = scope:recipient
						}
					}
				}
				has_situation_top_phase_parameter = claim_seeking_acceptance_bonus
			}
			add = 50
			desc = claim_seeking_acceptance_bonus_desc
		}
	}

	send_option = {
		is_shown = {
			scope:recipient != scope:puppet_or_actor
		}
		is_valid = {
			scope:puppet_or_actor = {
				has_usable_hook = scope:recipient
			}
			trigger_if = {
				limit = {
					scope:secondary_recipient ?= {
						is_ai = no
					}
				}
				scope:actor = { is_ai = no }
			}
		}
		flag = use_hook
		localization = EDUCATION_HOOK
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				trigger_if = {
					limit = {
						scope:actor = {
							is_ai = yes
						}
					}
					short_term_gold >= massive_gold_value
				}
				trigger_else = {
					gold >= major_gold_value
				}
			}
		}
		flag = donate_faith
		localization = DONATE_TO_THE_FAITH_INTERACTION_OPTION
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				dread >= medium_dread_value
			}
			scope:actor = {
				is_ai = no
			}
		}
		flag = threaten_priest
		localization = THREATEN_PRIEST_INTERACTION_OPTION
	}

	send_option = {
		is_valid = {
			NOT = {
				scope:recipient = {
					has_usable_hook = scope:puppet_or_actor
				}
			}
			scope:recipient = {
				can_add_hook = {
					target = scope:puppet_or_actor
					type = favor_hook
				}
			}
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				always = no
			}
		}
		flag = offer_hook
		localization = OFFER_HOOK_INTERACTION_OPTION
	}

	send_option = {
		is_shown = {
			pam_offer_pilgrimage_option_shown_trigger = { ACTOR = scope:puppet_or_actor }
		}
		is_valid = {
			pam_offer_pilgrimage_option_valid_trigger = { ACTOR = scope:puppet_or_actor }
		}
		flag = offer_pilgrimage
		localization = OFFER_PILGRIMAGE_INTERACTION_OPTION
	}

	should_use_extra_icon = {
		scope:puppet_or_actor = { has_usable_hook = scope:recipient }
	}

	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	ai_targets = {
		ai_recipients = head_of_faith
		ai_recipients = realm_priest_superior
		ai_recipients = realm_priest_top_superior
		ai_recipients = peer_vassals
		ai_recipients = vassals
		ai_recipients = councillors
		ai_recipients = liege
		ai_recipients = top_liege
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 48
		duchy = 36
		kingdom = 36
		empire = 36
		hegemony = 36
	}

	ai_will_do = {
		base = 10
		#Wants titles that should rightfully be yours
		modifier = {
			scope:target ?= {
				de_jure_liege ?= {
					holder ?= scope:puppet_or_actor
				}
			}
			add = 30
		}
		modifier = {
			scope:target ?= {
				tier >= scope:puppet_or_actor.highest_held_title_tier
			}
			add = 50
		}
		modifier = {
			scope:recipient = { save_temporary_scope_as = cleric }
			scope:target.holder ?= { save_temporary_scope_as = owner }
			clerical_hesitation_from_target_holder_value != 0
			add = {
				value = clerical_hesitation_from_target_holder_value
				multiply = 10
			}
		}
		#low tier titles are less tantalizing
		modifier = {
			scope:target ?= {
				tier < scope:puppet_or_actor.highest_held_title_tier_minus_one
			}
			factor = 0.5
		}
		modifier = {
			scope:puppet_or_actor = {
				highest_held_title_tier = tier_county
			}
			scope:target ?= {
				title_capital_county = {
					squared_distance = {
						target = scope:puppet_or_actor.capital_province
						value >= squared_distance_major
					}
				}
			}
			factor = 0.25
		}
		modifier = {
			scope:puppet_or_actor = {
				highest_held_title_tier = tier_duchy
			}
			scope:target ?= {
				title_capital_county = {
					squared_distance = {
						target = scope:puppet_or_actor.capital_province
						value >= squared_distance_large
					}
				}
			}
			factor = 0.25
		}
		modifier = {
			scope:puppet_or_actor = {
				highest_held_title_tier = tier_kingdom
			}
			scope:target ?= {
				title_capital_county = {
					squared_distance = {
						target = scope:puppet_or_actor.capital_province
						value >= squared_distance_huge
					}
				}
			}
			factor = 0.25
		}
		modifier = {
			scope:puppet_or_actor = {
				highest_held_title_tier >= tier_empire
			}
			scope:target ?= {
				title_capital_county = {
					squared_distance = {
						target = scope:puppet_or_actor.capital_province
						value >= squared_distance_massive
					}
				}
			}
			factor = 0.25
		}
	}
}

#Sell a fabricated diocese claim to a secular ruler
sell_claim_interaction = {
	category = interaction_category_diplomacy
	icon = sell_claim_interaction
	interface_priority = 35
	target_type = title
	target_filter = counties_of_faith
	target_source = puppet_or_actor
	show_all_targets = no
	notification_text = sell_claim_interaction_notification
	greeting = positive
	
	cooldown_against_recipient = { years = 3 }

	use_diplomatic_range = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes

	desc = sell_claim_interaction_desc

	cost = {
		piety = {
			value = pam_sell_claim_piety_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 144
		kingdom = 24
		empire = 24
		hegemony = 24
	}

	is_available = {
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			government_has_flag = government_is_theocracy
			faith ?= { has_doctrine_parameter = has_clerical_regions }
			OR = {
				any_held_title = { has_clerical_region = yes }
				faith.religious_head ?= this
			}
		}
		scope:puppet_or_actor ?= {
			NOT = { is_at_war_with = scope:recipient }
			this != scope:recipient
		}
		scope:recipient = {
			is_ruler = yes
			NOT = { government_has_flag = government_is_theocracy }
			faith ?= scope:puppet_or_actor.faith
			highest_held_title_tier >= tier_county
		}
	}

	is_valid_showing_failures_only = {
		# cost = { piety } is only charged to scope:actor, so a puppeteer's cleric is checked here instead
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= pam_sell_claim_piety_cost_value
			}
		}
		scope:puppet_or_actor = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
				adult = yes
			}
			NOT = { has_trait = excommunicated }
			trigger_if = {
				limit = {
					can_add_hook = {
						target = scope:recipient
						type = favor_hook
					}
				}
				scope:recipient = {
					gold >= minor_gold_value
				}
			}
			trigger_else = {
				scope:recipient = {
					gold >= pam_sell_claim_gold_cost_value
				}
			}
		}
		scope:recipient = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
				adult = yes
			}
			NOT = { has_trait = excommunicated }
		}
	}

	can_be_picked_title = {
		pam_can_sell_claim_on_target_trigger = yes

		trigger_if = {
			limit = { scope:sell_claim_gold_and_hook = no }
			scope:recipient = {
				gold >= pam_sell_claim_gold_cost_value
			}
		}
	}

	# can_be_picked_title is picker-only and is not rechecked on send
	has_valid_target_showing_failures_only = {
		pam_can_sell_claim_on_target_trigger = yes
	}

	on_accept = {
		scope:puppet_or_actor = {
			sell_claim_interaction_effect = yes
		}
	}

	on_decline = {
		if = {
			limit = {
				scope:recipient = {
					is_ai = no
				}
			}
			scope:puppet_or_actor = {
				add_opinion = {
					modifier = refusal_opinion
					target = scope:recipient
					opinion = -10
				}
			}
		}
	}

	options_heading = sell_claim_payment_heading
	send_options_exclusive = yes

	send_option = {
		flag = sell_claim_gold
		localization = SELL_CLAIM_GOLD_OPTION
		is_valid = {
			scope:recipient = {
				gold >= pam_sell_claim_gold_cost_value
			}
		}
	}

	send_option = {
		flag = sell_claim_gold_and_hook
		localization = SELL_CLAIM_GOLD_AND_HOOK_OPTION
		is_valid = {
			scope:actor = {
				can_add_hook = {
					target = scope:recipient
					type = favor_hook
				}
			}
		}
	}

	ai_accept = {
		base = 10

		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:puppet_or_actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		modifier = {
			add = 30
			scope:recipient = {
				ai_greed >= medium_positive_ai_value
			}
			desc = SELL_CLAIM_GREED_REASON
		}
		modifier = {
			add = -50
			scope:sell_claim_gold = yes
			scope:recipient = {
				gold < pam_sell_claim_gold_cost_value
			}
			desc = SELL_CLAIM_CANNOT_AFFORD_REASON
		}
		modifier = {
			add = 20
			scope:sell_claim_gold_and_hook = yes
			scope:recipient = {
				ai_greed >= low_positive_ai_value
			}
			desc = SELL_CLAIM_CHEAPER_OPTION_REASON
		}
		modifier = {
			add = 15
			scope:recipient = {
				any_neighboring_top_liege_realm_owner = {
					this = scope:puppet_or_actor
				}
			}
			scope:target ?= {
				any_neighboring_county = {
					holder.top_liege ?= scope:recipient
				}
			}
			desc = SELL_CLAIM_NEIGHBORING_TITLE_REASON
		}
		modifier = {
			add = 20
			is_in_same_clerical_region_as_trigger = { TARGET = scope:puppet_or_actor }
			desc = SELL_CLAIM_SAME_CLERICAL_REGION_REASON
		}
		modifier = { # Friends
			add = 15
			scope:recipient = {
				has_relation_friend = scope:puppet_or_actor
			}
			desc = WE_ARE_FRIENDS
		}
		modifier = { # BFFs
			add = 25
			scope:recipient = {
				has_relation_best_friend = scope:puppet_or_actor
			}
			desc = WE_ARE_BEST_FRIENDS
		}
		modifier = { # Their rite supports this
			add = 20
			scope:recipient = {
				rite = { rite_has_tenet = tenet_simony }
			}
			desc = SIMONY_RITE_REASON
		}
		modifier = { # Your or their rite condemns it
			add = -50
			OR = {
				scope:actor = {
					rite = {
						has_tenet_status = {
							tenet = tenet_simony
							status = prohibited
						}
					}
				}
				scope:recipient = {
					rite = {
						has_tenet_status = {
							tenet = tenet_simony
							status = prohibited
						}
					}
				}
			}
			desc = SIMONY_IS_PROHIBITED
		}
		modifier = {
			add = {
				add = -5
				multiply = scope:recipient.piety_level
			}
			scope:recipient.piety_level > 1
			desc = RECIPIENT_IS_PIOUS
		}
	}

	ai_will_do = {
		base = 10

		modifier = {
			add = scope:puppet_or_actor.ai_greed
		}
		modifier = {
			add = 25
			scope:puppet_or_actor = {
				debt_level > 0
			}
		}
		modifier = {
			add = -50
			scope:puppet_or_actor = {
				has_trait = zealous
			}
		}
		modifier = {
			add = 25
			scope:puppet_or_actor = {
				has_trait = cynical
			}
		}
		modifier = {
			add = -50
			scope:puppet_or_actor = {
				rite = {
					has_tenet_status = {
						tenet = tenet_simony
						status = prohibited
					}
				}
			}
		}
		modifier = {
			add = 20
			scope:puppet_or_actor = {
				OR = {
					has_relation_friend = scope:recipient
					has_relation_best_friend = scope:recipient
					opinion = {
						target = scope:recipient
						value >= high_positive_opinion
					}
				}
			}
		}
		modifier = {
			add = -60
			scope:puppet_or_actor = {
				OR = {
					has_relation_rival = scope:recipient
					has_relation_nemesis = scope:recipient
					opinion = {
						target = scope:recipient
						value <= medium_negative_opinion
					}
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = rulers_in_clerical_region
	}

	ai_target_quick_trigger = {
		adult = yes
	}
}

#Hand one of my own claims to a ruler under my spiritual care
gift_claim_interaction = {
	category = interaction_category_diplomacy
	icon = gift_claim_interaction
	common_interaction = no
	interface_priority = 34
	target_type = title
	target_filter = claimed_titles
	target_source = puppet_or_actor
	notification_text = gift_claim_interaction_notification
	greeting = positive

	cooldown_against_recipient = { years = 3 }

	use_diplomatic_range = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes

	desc = gift_claim_interaction_desc

	cost = {
		piety = medium_piety_value
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 48
		duchy = 48
		kingdom = 24
		empire = 24
		hegemony = 24
	}

	is_available = {
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			government_has_flag = government_is_theocracy
			faith ?= { has_doctrine_parameter = has_clerical_regions }
			OR = {
				any_held_title = { has_clerical_region = yes }
				faith.religious_head ?= this
			}
			is_adult = yes
			is_ruler = yes
		}
		scope:puppet_or_actor ?= {
			NOT = { is_at_war_with = scope:recipient }
			this != scope:recipient
		}
		scope:recipient = {
			is_ruler = yes
			faith ?= scope:puppet_or_actor.faith
			highest_held_title_tier >= tier_county
		}
	}

	is_valid_showing_failures_only = {
		custom_tooltip = {
			text = gift_claim_must_have_valid_claim_tt
			scope:puppet_or_actor ?= {
				any_claim = {
					save_temporary_scope_as = gift_claim_candidate_title
					pam_gift_claim_valid_title_trigger = { TITLE = scope:gift_claim_candidate_title }
				}
			}
		}
		scope:puppet_or_actor = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
				adult = yes
			}
			NOT = { has_trait = excommunicated }
		}
		scope:recipient = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
				adult = yes
			}
			NOT = { has_trait = excommunicated }
		}
		custom_tooltip = {
			text = gift_claim_recipient_must_be_in_clerical_region_tt
			scope:puppet_or_actor ?= {
				OR = {
					pam_gift_claim_recipient_in_own_clerical_region_trigger = { TARGET = scope:recipient }
					faith.religious_head ?= this
				}
			}
		}
	}

	can_be_picked_title = {
		scope:target ?= { tier = tier_county }
	}

	has_valid_target_showing_failures_only = {
		pam_can_gift_claim_on_target_trigger = yes
	}

	on_accept = {
		scope:puppet_or_actor = {
			gift_claim_interaction_effect = yes
		}
	}

	ai_accept = {
		base = 100
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = 25
			scope:puppet_or_actor = {
				OR = {
					has_relation_friend = scope:recipient
					has_relation_best_friend = scope:recipient
					opinion = {
						target = scope:recipient
						value >= high_positive_opinion
					}
				}
			}
		}
		modifier = {
			add = 25
			scope:puppet_or_actor = {
				has_trait = generous
			}
		}
		modifier = {
			add = 15
			scope:puppet_or_actor = {
				has_trait = humble
			}
		}
		modifier = {
			add = -60
			scope:puppet_or_actor = {
				OR = {
					has_relation_rival = scope:recipient
					has_relation_nemesis = scope:recipient
					opinion = {
						target = scope:recipient
						value <= medium_negative_opinion
					}
				}
			}
		}
		modifier = {
			factor = 0
			NOT = {
				scope:target = {
					is_neighbor_to_realm = scope:recipient
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = rulers_in_clerical_region
	}

	ai_target_quick_trigger = {
		adult = yes
	}
}

#Give me a strong claim, powerful clergy guy
#In order to be able to pick a clergy member, they had to be put into secondary recipient list
#Unfortunately, that has created a strange scenario where the claim holder is the recipient
#I've prevented them seeing anything from that though
ecclesiastic_grant_claim_interaction = {
	category = interaction_category_diplomacy
	icon = icon_clergy_claim_title

	desc = ecclesiastic_grant_claim_interaction_desc
	notification_text = ecclesiastic_grant_claim_interaction_notification
	target_type = title
	target_filter = domain_titles
	target_source = recipient
	interface_priority = 50
	ai_min_reply_days = 1
	ai_max_reply_days = 2
	popup_on_receive = no

	use_diplomatic_range = yes

	cooldown_against_recipient = { years = 2 }

	redirect = {
		if = {
			limit = {
				exists = scope:secondary_recipient
			}
			scope:secondary_recipient = { save_scope_as = intermediary }
		}
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				piety >= major_piety_value
				is_playable_character = yes
				is_at_war = no
				OR = {
					ai_greed >= medium_positive_ai_value
					ai_has_warlike_personality = yes
				}
				NOT = { has_trait = excommunicated }
			}
			#Has theocratic head of faith or spiritual clergy
			pam_beseech_claims_access_trigger = yes
			is_ruler = yes
			is_landed = yes
			NOR = {
				government_has_mechanic = theocracy
				is_at_war_with = scope:recipient
			}
		}
		scope:recipient = {
			is_ruler = yes
			primary_title.tier > tier_barony
			faith ?= scope:puppet_or_actor.faith
			any_held_title = {
				is_landless_type_title = no
			}
			NOR = {
				target_is_same_character_or_above = scope:puppet_or_actor
				this = scope:actor
				scope:puppet_or_actor.religious_head_or_challenger ?= scope:recipient
			}
		}
	}

	populate_recipient_list = {
		scope:puppet_or_actor ?= {
			faith = {
				organization = {
					every_organization_member = {
						limit = {
							claim_valid_faith_subordinate_trigger = yes
						}
						add_to_list = characters
					}
				}
				if = {
					limit = {
						religious_head ?= {
							clergy_claims_hof_trigger = yes
						}
					}
					religious_head = {
						add_to_list = characters
					}
				}
			}
		}
	}

	can_be_picked_title = {
		scope:target = {
			tier >= tier_county
			is_landless_type_title = no
		}
		NOT = {
			scope:puppet_or_actor = { has_claim_on = scope:target }
		}
		trigger_if = {
			limit = {
				scope:secondary_recipient ?= {
					this != scope:puppet_or_actor.religious_head_or_challenger
				}
			}
			custom_tooltip = {
				text = clergy_claims_hof_only_tt
				scope:target = { tier < tier_kingdom }
			}
		}
	}
	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			clergy_interaction_generic_piety_level_or_puppet_req_trigger = yes
			
			trigger_if = {
				limit = { is_valid_for_legitimacy_change = yes }
				trigger_if = {
					limit = {
						highest_held_title_tier >= tier_kingdom
					}
					legitimacy_level >= 4
				}
				trigger_else = {
					legitimacy_level >= 3
				}
				custom_tooltip = {
					text = above_expected_legitimacy_tt
					any_vassal = {
						count = all
						trigger_if = {
							limit = {
								is_ai = yes
							}
							scope:puppet_or_actor = {
								meets_legitimacy_expectation_of = prev
							}
						}
					}
				}
			}
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				at_war = no
			}
			NOT = { has_trait = excommunicated }
		}
		scope:recipient = {
			faith.religion = scope:puppet_or_actor.faith.religion
			NOR = {
				this = scope:puppet_or_actor
				has_strong_hook = scope:puppet_or_actor
			}
			#Head of faith is checked first because searching the organization is far more expensive
			trigger_if = {
				limit = {
					NAND = {
						scope:puppet_or_actor.faith = { has_doctrine_parameter = spiritual_head_of_faith }
						OR = {
							NOT = { exists = scope:puppet_or_actor.religious_head_or_challenger }
							scope:puppet_or_actor.religious_head_or_challenger ?= { clergy_claims_hof_trigger = yes }
						}
					}
					NOT = {
						scope:puppet_or_actor.faith = {
							organization = {
								any_organization_member = {
									claim_valid_faith_subordinate_trigger = yes
								}
							}
						}
					}
				}
				#Neither route is open at this point, so the two below only report which one is missing
				custom_tooltip = {
					text = responsible_cleric_tt
					scope:puppet_or_actor.faith = { has_doctrine_parameter = spiritual_head_of_faith }
				}
				trigger_if = {
					limit = {
						exists = scope:puppet_or_actor.religious_head_or_challenger
					}
					custom_tooltip = {
						text = clergy_claim_hof_available_tt
						scope:puppet_or_actor.religious_head_or_challenger = {
							clergy_claims_hof_trigger = yes
						}
					}
				}
			}
		}
		trigger_if = { # Can't request on titles you already have a claim on
			limit = {
				scope:target ?= {
					any_claimant = { this = scope:puppet_or_actor }
				}
			}
			custom_description = {
				text = buy_claim_has_pressed_claim_already
				always = no
			}
		}
		trigger_if = { # Can't request claims on baronies
			limit = {
				scope:target ?= { tier = tier_barony }
			}
			custom_description = {
				text = buy_claim_has_pressed_claim_already
				always = no
			}
		}
		trigger_if = { # Can't buy claims on head of faith titles
			limit = {
				scope:target ?= { is_head_of_faith = yes }
			}
			custom_description = {
				text = buy_claim_no_religious_titles
				always = no
			}
		}
		trigger_if = { # Can't buy claims on noble families
			limit = {
				scope:target ?= { is_noble_family_title = yes }
			}
			custom_description = {
				text = buy_claim_no_noble_family_titles
				always = no
			}
		}
		trigger_if = { # Can't buy claims on landless adventurer titles
			limit = {
				scope:target ?= { has_variable = adventurer_creation_reason }
			}
			custom_description = {
				text = buy_claim_no_landless_adventurer_title
				always = no
			}
		}
		tgp_blocked_action_against_tenno_trigger = {
			ACTOR = scope:puppet_or_actor
			TARGET = scope:recipient
		}
		pam_not_promised_pilgrimage_trigger = { ACTOR = scope:puppet_or_actor }
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= pam_ecclesiastic_grant_claim_cost_value
			}
		}
	}

	on_send = {
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				if = {
					limit = { pam_ecclesiastic_grant_claim_cost_value > 0 }
					add_piety = {
						value = {
							add = pam_ecclesiastic_grant_claim_cost_value
							max = piety
							multiply = -1
						}
					}
				}
			}
		}
		if = {
			limit = {
				scope:secondary_recipient = {
					is_ai = no
				}
			}
			#Player clergy can decide whether to grant claim
			scope:secondary_recipient = {
				trigger_event = pam_interactions_events.0023
			}
		}
		else = {
			scope:puppet_or_actor = {
				show_as_tooltip = {
					ecclesiastic_grant_claim_interaction_effect = yes
				}
				trigger_event = pam_interactions_events.0020
				scope:recipient = {
					#Event where they're informed
					trigger_event = pam_interactions_events.0022
				}
			}
		}
	}

	on_decline = {
		scope:puppet_or_actor = {
			trigger_event = pam_interactions_events.0021
		}
	}

	cost = {
		piety = {
			value = pam_ecclesiastic_grant_claim_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	auto_accept = {
		OR = {
			#player recipients can close interaction, need auto_accept
			scope:recipient = {
				is_ai = no
			}
			# Using a hook should make him auto accept
			AND = {
				exists = scope:secondary_recipient
				custom_description = {
					text = "spending_hook"
					subject = scope:puppet_or_actor
					object = scope:secondary_recipient
					scope:use_hook = yes
					scope:puppet_or_actor = { has_strong_hook = scope:secondary_recipient }
				}
			}
		}
	}

	ai_accept = {
		base = 0

		modifier = { # By God Alone - Secular Faith: the petitioner holds the ear of the clergy
			add = 25
			desc = pam_sf_ear_of_clergy_accept_reason
			trigger = {
				scope:puppet_or_actor = { has_character_modifier = pam_sf_ear_of_clergy_modifier }
			}
		}

		modifier = {
			scope:puppet_or_actor = {
				legitimacy_level >= 5
			}
			add = 20
			desc = HIGH_LEGITIMACY_REASON
		}
		#Your gender is scorned by their faith
		modifier = {
			OR = {
				AND = {
					scope:puppet_or_actor = {
						is_female = yes
					}
					scope:recipient = {
						is_female = no
						rite = {
							rite_has_parameter = male_dominated_law
						}
					}
				}
				AND = {
					scope:puppet_or_actor = {
						is_male = yes
					}
					scope:recipient = {
						is_male = no
						rite = {
							rite_has_parameter = female_dominated_law
						}
					}
				}
			}
			add = -20
			desc = NON_DOMINANT_GENDER_REASON
		}
		# Weak hook: extra points
		modifier = {
			scope:use_hook = yes
			add = 200
			exists = scope:secondary_recipient
			scope:puppet_or_actor = { NOT = { has_strong_hook = scope:secondary_recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}
		#Malus to king+ trying to gather more king+ titles without increasing their tier
		modifier = {
			exists = scope:target
			scope:target.tier >= tier_kingdom
			scope:puppet_or_actor = {
				highest_held_title_tier >= tier_kingdom
				highest_held_title_tier >= scope:target.tier
			}
			desc = KING_PLUS_TARGETING_KINGDOM_REASON
			add = -100
		}

		#Acceptance modifiers for all these ask the clergy for stuff interactions
		general_secular_to_ecclesiastic_acceptance_secondary_recipient_modifier = yes

		#Acceptance modifiers related to clergy's relation to target title and its possible holders
		title_acquisition_clerical_acceptance_secondary_recipient_modifier = yes

		#Interaction options
		modifier = {
			add = {
				value = 20
				multiply = scope:puppet_or_actor.highest_held_title_tier
			}
			scope:offer_hook = yes
			desc = OFFER_HOOK_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 25
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			exists = scope:secondary_recipient
			scope:puppet_or_actor.medium_gold_value < scope:secondary_recipient.miniscule_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 50
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			exists = scope:secondary_recipient
			scope:puppet_or_actor.medium_gold_value < scope:secondary_recipient.medium_gold_value
			scope:puppet_or_actor.medium_gold_value >= scope:secondary_recipient.miniscule_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 75
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			exists = scope:secondary_recipient
			scope:puppet_or_actor.medium_gold_value >= scope:secondary_recipient.medium_gold_value
			scope:puppet_or_actor.medium_gold_value < scope:secondary_recipient.massive_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 100
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			exists = scope:secondary_recipient
			scope:puppet_or_actor.medium_gold_value >= scope:secondary_recipient.massive_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			exists = scope:secondary_recipient
			add = {
				value = 30
				#Modify value by how scary actor is. Are they higher tier than recipient? Are they neighbors?
				if = {
					limit = {
						scope:puppet_or_actor.highest_held_title_tier > scope:secondary_recipient.highest_held_title_tier
					}
					add = {
						value = scope:puppet_or_actor.highest_held_title_tier
						subtract = scope:secondary_recipient.highest_held_title_tier
						multiply = 20
					}
				}
				else_if = {
					limit = {
						scope:puppet_or_actor.highest_held_title_tier < scope:secondary_recipient.highest_held_title_tier_minus_one
					}
					add = -25
				}
				else_if = {
					limit = {
						scope:puppet_or_actor.highest_held_title_tier < scope:secondary_recipient.highest_held_title_tier
					}
					add = -10
				}
				if = {
					limit = {
						scope:puppet_or_actor = {
							OR = {
								is_liege_or_above_of = scope:secondary_recipient
								scope:secondary_recipient ?= {
									any_held_title = {
										is_neighbor_to_realm = scope:puppet_or_actor
									}
								}
								scope:secondary_recipient.capital_county.holder ?= {
									OR = {
										this = scope:puppet_or_actor
										this = scope:recipient
										any_liege_or_above = {
											this = scope:puppet_or_actor
										}
									}
								}
							}
						}
					}
					multiply = 2
				}
				else_if = {
					limit = {
						OR = {
							scope:puppet_or_actor.liege ?= scope:secondary_recipient.liege
							scope:recipient = {
								is_liege_or_above_of = scope:secondary_recipient
							}
						}
					}
					multiply = 1.5
				}
			}
			scope:threaten_priest = yes
			desc = THREATEN_PRIEST_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = pam_offer_pilgrimage_acceptance_value
			scope:offer_pilgrimage = yes
			desc = OFFER_PILGRIMAGE_INTERACTION_OPTION_REASON
		}

		#Cleric hesitating because of comparison to target's holder
		modifier = {
			exists = scope:target.holder
			scope:secondary_recipient ?= { save_temporary_scope_as = cleric }
			scope:recipient = { save_temporary_scope_as = owner }
			clerical_hesitation_from_target_holder_value != 0
			desc = RECIPIENTS_ESTIMATION_OF_TARGET_HOLDER_PIETY_REASON
			add = {
				value = clerical_hesitation_from_target_holder_value
				multiply = -20
			}
		}
		modifier = {
			scope:secondary_recipient ?= { save_temporary_scope_as = cleric }
			scope:recipient = { save_temporary_scope_as = owner }
			scope:recipient = { is_independent_ruler = no }
			scope:puppet_or_actor = { is_independent_ruler = no }
			scope:recipient.top_liege ?= scope:puppet_or_actor.top_liege
			NOR = {
				scope:puppet_or_actor.liege = scope:recipient.liege
				scope:recipient.liege = scope:puppet_or_actor
				scope:puppet_or_actor.top_liege = scope:recipient
			}
			clerical_hesitation_from_potential_defender_value != 0
			desc = RECIPIENTS_ESTIMATION_OF_TARGET_LIEGE_PIETY_REASON
			add = {
				value = clerical_hesitation_from_potential_defender_value
				multiply = -20
			}

		}
		modifier = {
			scope:secondary_recipient ?= { save_temporary_scope_as = cleric }
			scope:recipient = { save_temporary_scope_as = owner }
			scope:recipient = {
				is_independent_ruler = no
				NOT = {
					top_liege = scope:puppet_or_actor.top_liege
				}
			}
			clerical_hesitation_from_potential_defender_value != 0
			desc = RECIPIENTS_ESTIMATION_OF_TARGET_TOP_LIEGE_PIETY_REASON
			add = {
				value = clerical_hesitation_from_potential_defender_value
				multiply = -20
			}

		}
		modifier = {
			exists = scope:secondary_recipient
			scope:secondary_recipient ?= { save_temporary_scope_as = cleric }
			scope:recipient = {
				save_temporary_scope_as = owner
			}
			scope:target ?= {
				de_jure_liege ?= {
					exists = holder
					NOR = {
						holder = scope:secondary_recipient
						holder = scope:puppet_or_actor
						holder = scope:recipient
					}
				}
			}
			clerical_hesitation_from_potential_defender_value != 0
			desc = RECIPIENTS_ESTIMATION_OF_TARGET_DE_JURE_LIEGE_PIETY_REASON
			add = {
				value = clerical_hesitation_from_potential_defender_value
				multiply = -20
			}
		}

		#Have the Sanctioned Loopholes perk
		modifier = {
			scope:puppet_or_actor = { has_perk = sanctioned_loopholes_perk }
			desc = SANCTIONED_LOOPHOLES_REASON
			add = 200
		}

		#Christian situation
		modifier = {
			situation:the_christian_church ?= {
				any_participant_group = { # Both characters are involved in the situation
					any_situation_group_participant = {
						this = scope:puppet_or_actor
					}
					trigger_if = {
						limit = { scope:recipient = { is_ruler = yes } }
						any_situation_group_participant = {
							this = scope:recipient
						}
					}
				}
				has_situation_top_phase_parameter = claim_seeking_acceptance_bonus
			}
			add = 50
			desc = claim_seeking_acceptance_bonus_desc
		}
	}

	send_option = {
		is_shown = {
			exists = scope:secondary_recipient
			scope:secondary_recipient != scope:puppet_or_actor
		}
		is_valid = {
			scope:puppet_or_actor = {
				has_usable_hook = scope:secondary_recipient
			}
			trigger_if = {
				limit = {
					scope:secondary_recipient = {
						is_ai = no
					}
				}
				scope:actor = { is_ai = no }
			}
		}
		flag = use_hook
		localization = EDUCATION_HOOK
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				trigger_if = {
					limit = {
						scope:actor = {
							is_ai = yes
						}
					}
					short_term_gold >= massive_gold_value
				}
				trigger_else = {
					gold >= major_gold_value
				}
			}
		}
		flag = donate_faith
		localization = DONATE_TO_THE_FAITH_INTERACTION_OPTION
	}

	send_option = {
		is_valid = {
			exists = scope:secondary_recipient
			scope:puppet_or_actor = {
				dread >= medium_dread_value
				scope:actor = { is_ai = no }
			}
		}
		flag = threaten_priest
		localization = THREATEN_PRIEST_INTERACTION_OPTION
	}

	send_option = {
		is_valid = {
			NOT = {
				scope:secondary_recipient ?= {
					has_usable_hook = scope:puppet_or_actor
				}
			}
			scope:secondary_recipient ?= {
				can_add_hook = {
					target = scope:puppet_or_actor
					type = favor_hook
				}
			}
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				always = no
			}
		}
		flag = offer_hook
		localization = OFFER_HOOK_INTERACTION_OPTION
	}

	send_option = {
		is_shown = {
			pam_offer_pilgrimage_option_shown_trigger = { ACTOR = scope:puppet_or_actor }
		}
		is_valid = {
			pam_offer_pilgrimage_option_valid_trigger = { ACTOR = scope:puppet_or_actor }
		}
		flag = offer_pilgrimage
		localization = OFFER_PILGRIMAGE_INTERACTION_OPTION
	}

	should_use_extra_icon = {
		scope:puppet_or_actor = { has_usable_hook = scope:recipient }
	}

	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = peer_vassals
		ai_recipients = liege
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 120
		duchy = 36
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = scope:puppet_or_actor.ai_greed
		}

		modifier = {
			add = scope:target.tier
		}

		modifier = {
			add = 500
			has_variable = conqueror
			NOR = {
				has_relation_friend = scope:recipient
				has_relation_lover = scope:recipient
			}
		}

		modifier = {
			add = -100
			scope:puppet_or_actor = {
				OR = {
					has_relation_friend = scope:recipient
					has_relation_lover = scope:recipient
					opinion = {
						target = scope:recipient
						value >= high_positive_opinion
					}
				}
			}
		}

		#Wants titles that should rightfully be yours
		modifier = {
			scope:target = {
				de_jure_liege ?= {
					holder ?= scope:puppet_or_actor
				}
			}
			add = 10
		}
		modifier = {
			scope:target = {
				OR = {
					any_direct_de_jure_vassal_title = {
						holder ?= scope:puppet_or_actor
					}
					any_de_jure_county = {
						any_neighboring_county = {
							OR = {
								holder = scope:puppet_or_actor
								holder = {
									any_liege_or_above = {
										this = scope:puppet_or_actor
									}
								}
							}
						}
					}
				}
			}
			add = 10
		}
		modifier = {
			scope:target = {
				tier >= scope:puppet_or_actor.highest_held_title_tier
			}
			factor = 2
		}
		modifier = {
			scope:secondary_recipient = { save_temporary_scope_as = cleric }
			scope:recipient = { save_temporary_scope_as = owner }
			clerical_hesitation_from_target_holder_value != 0
			add = {
				value = clerical_hesitation_from_target_holder_value
				multiply = 5
			}
		}
		modifier = {
			scope:puppet_or_actor = {
				has_dread_level_towards = {
					target = scope:recipient
					level >= 1
				}
			}
			factor = 0.25
		}
		modifier = {
			scope:puppet_or_actor = {
				has_dread_level_towards = {
					target = scope:recipient
					level >= 2
				}
			}
			factor = 0
		}
		modifier = {
			scope:secondary_recipient ?= {
				this = scope:puppet_or_actor.religious_head
			}
			scope:target.tier < tier_duchy
			factor = 0
		}

		modifier = {
			factor = 0
			NOT = {
				scope:target = {
					is_neighbor_to_realm = scope:puppet_or_actor
				}
			}
		}
		#Don't bother player priests unless you are worthy
		modifier = {
			NOT = { pam_should_bother_clergy_interaction_trigger = { PRIEST = scope:secondary_recipient } }
			factor = 0
		}
		modifier = {
			factor = 0
			exists = scope:secondary_recipient
			#AI will auto-accept when targeting players, so detailed factors are in here
			pam_clergy_title_interaction_player_recipient_auto_accept_trigger = yes
		}
	}
}

buy_ecclesiastical_title_interaction = {
	category = interaction_category_religion
	icon = sell_claim_interaction # Shared with sell_claim_interaction: a clerical shield and cross-stamped coins reads for both sides of the trade
	interface_priority = 45

	use_diplomatic_range = yes
	ai_maybe = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes

	desc = buy_ecclesiastical_title_interaction_desc
	target_type = title
	target_filter = recipient_domain_titles

	redirect = {
		scope:actor = {
			if = {
				limit = {
					government_has_flag = government_is_theocracy
				}
				save_scope_as = secondary_recipient
			}
		}
	}

	populate_recipient_list = {
		scope:actor = {
			if = {
				limit = {
					NOT = { government_has_flag = government_is_theocracy }
				}
				add_to_list = characters
				if = {
					limit = {
						exists = cp:councillor_court_chaplain
						cp:councillor_court_chaplain.faith = scope:actor.faith
						NOT = {
							cp:councillor_court_chaplain = {
								any_held_title = { has_clerical_region = yes }
							}
						}
					}
					cp:councillor_court_chaplain = { add_to_list = characters }
				}
				every_courtier = {
					limit = {
						is_ai = yes
						is_physically_able_adult = yes
						is_faith_dominant_gender = yes
						is_imprisoned = no
						is_ruler = no
						faith = scope:actor.faith
					}
					add_to_list = characters
				}
			}
		}
	}

	is_available = {
		faith ?= { has_doctrine_parameter = has_clerical_regions }
		is_adult = yes
		NOT = { has_trait = incapable }
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:recipient = {
			faith ?= scope:actor.faith
			pam_government_is_religious_playable_trigger = yes
			is_ai = yes
			any_held_title = {
				has_clerical_region = yes
				is_head_of_faith = no
			}
			NOT = { this = scope:actor }
			# Neither the Head of Faith nor an antipope sells off clerical titles
			NOT = { scope:actor.faith.religious_head ?= this }
			pam_is_antipope_trigger = no
		}
	}

	is_valid = {
		pam_actor_has_simony_trigger = yes
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_imprisoned = no
			is_at_war = no
			is_incapable = no
		}
		pam_not_promised_pilgrimage_trigger = { ACTOR = scope:actor }
		trigger_if = { # A theocratic buyer keeps the see themselves, so they cannot already hold one
			limit = {
				scope:actor = { government_has_flag = government_is_theocracy }
			}
			custom_description = {
				text = buy_ecclesiastical_title_already_holds_clerical_region_tt
				subject = scope:actor
				scope:actor = {
					NOT = { any_held_title = { has_clerical_region = yes } }
				}
			}
		}
	}

	can_be_picked_title = {
		scope:target = {
			holder = scope:recipient
			has_clerical_region = yes
			is_head_of_faith = no
			tier >= tier_county
		}
	}

	#Use hook
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
			scope:recipient = {
				NOT = { is_imprisoned_by = scope:actor }
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
		}
	}

	on_accept = {
		scope:actor = {
			if = {
				limit = {
					scope:hook = yes
					has_usable_hook = scope:recipient
				}
				use_hook = scope:recipient
			}
		}
		pam_buy_ecclesiastical_title_interaction_effect = yes
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = buy_ecclesiastical_title_interaction_decline_toast
				right_icon = scope:recipient
				scope:recipient = {
					add_opinion = {
						target = scope:actor
						modifier = impious_opinion
						opinion = -25
					}
				}
			}
		}
	}

	ai_accept = {
		base = -50
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1.0
			desc = AI_OPINION_REASON
		}
		modifier = {
			scope:hook = yes
			add = 20
			scope:actor = { NOT = { has_strong_hook = scope:recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = { # Legitimacy
			add = 20
			scope:actor = {
				legitimacy_level >= 5
			}
			desc = HIGH_LEGITIMACY_REASON
		}
		modifier = { # Their rite supports this
			add = 20
			scope:recipient = {
				rite = { rite_has_tenet = tenet_simony }
			}
			desc = SIMONY_RITE_REASON
		}
		modifier = { # Peace of God: a see changing hands by sale rather than by siege
			add = 30
			scope:recipient.rite ?= {
				rite_has_parameter = tenet_peace_of_god_clergy_peacemaking
			}
			desc = pam_peace_of_god_clergy_peacemaking_accept_reason
		}
		modifier = { # Receiver's piety level
			exists = scope:secondary_recipient
			add = {
				add = 5
				multiply = scope:secondary_recipient.piety_level
			}
			scope:secondary_recipient.piety_level > 1
			desc = SECONDARY_RECIPIENT_IS_PIOUS
		}
		modifier = { # Their piety level
			add = {
				add = 5
				multiply = scope:recipient.piety_level
			}
			scope:recipient.piety_level > 1
			desc = RECIPIENT_IS_PIOUS
		}
		modifier = { # Friends
			add = 15
			scope:recipient = {
				has_relation_friend = scope:actor
			}
			desc = WE_ARE_FRIENDS
		}
		modifier = { # BFFs
			add = 25
			scope:recipient = {
				has_relation_best_friend = scope:actor
			}
			desc = WE_ARE_BEST_FRIENDS
		}
		modifier = { # Dread
			add = 50
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = { # Greed
			add = 20
			scope:recipient = {
				has_trait = greedy
			}
			desc = ACTIVITY_GUEST_GREEDY_REASON
		}
		modifier = { # Ambitious
			add = -20
			scope:recipient = {
				has_trait = ambitious
			}
			desc = ACTIVITY_GUEST_AMBITIOUS_REASON
		}
		modifier = { # They are bankrupt
			add = {
				value = 40
				multiply = scope:recipient.debt_level
			}
			trigger = {
				scope:recipient = {
					OR = {
						debt_level > 0
						treasury_debt_level > 0
					}
				}
			}
			desc = PURCHASE_LAND_IS_IN_DEBT_REASON
		}

	}

	ai_targets = {
		ai_recipients = clerical_region_rulers_in_realm
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 72
		duchy = 36
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_will_do = {
		base = 10

		modifier = {
			add = scope:actor.ai_greed
		}

		modifier = { # Don't steal from your friend
			add = -100
			scope:actor = {
				OR = {
					has_relation_friend = scope:recipient
					has_relation_lover = scope:recipient
					opinion = {
						target = scope:recipient
						value >= high_positive_opinion
					}
				}
			}
		}

		modifier = { # Give to your close family
			add = 25
			scope:actor != scope:secondary_recipient
			scope:secondary_recipient = {
				this != scope:actor.primary_heir # But not your heir
				is_close_or_extended_family_of = scope:actor
			}
		}

		modifier = { # You like the secondary recipient
			add = 20
			scope:actor = {
				this != scope:secondary_recipient
				OR = {
					has_relation_friend = scope:secondary_recipient
					has_relation_lover = scope:secondary_recipient
					opinion = {
						target = scope:secondary_recipient
						value >= high_positive_opinion
					}
				}
			}
		}
	}
}

#GET THAT JERK TO GIVE ME MY CLAIMED LAND, POWERFUL CLERGY GUY
ecclesiastic_transfer_land_interaction = {
	category = interaction_category_diplomacy
	icon = icon_clergy_move_lands

	desc = ecclesiastic_transfer_land_interaction_desc
	notification_text = ecclesiastic_transfer_land_interaction_notification
	target_type = title
	target_filter = realm_titles
	target_source = recipient
	interface_priority = 75
	common_interaction = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 2
	popup_on_receive = no

	use_diplomatic_range = yes

	cooldown_against_recipient = { years = 2 }

	is_available = {
		has_legitimacy = yes
		trigger_if = {
			limit = {
				is_ai = yes
			}
			piety >= major_piety_value
			is_playable_character = yes
			is_at_war = no
			OR = {
				ai_greed >= medium_positive_ai_value
				ai_has_warlike_personality = yes
			}
			NOT = { has_trait = excommunicated }
		}
		#Has theocratic head of faith or spiritual clergy
		pam_ecclesiastic_transfer_land_access_trigger = yes
	}
	redirect = {
		if = {
			limit = {
				exists = scope:secondary_recipient
			}
			scope:secondary_recipient = { save_scope_as = intermediary }
		}
		#You need to negotiate with the person you would otherwise be warring
		if = {
			limit = {
				scope:recipient = {
					is_independent_ruler = no
					#If you have the same liege, you can fight each other
					NOT = {
						scope:actor.liege ?= scope:recipient.liege
					}
				}
			}
			#You are in the same realm, at different levels. Who is on your level?
			if = {
				limit = {
					scope:actor.top_liege = scope:recipient.top_liege
				}
				scope:recipient = {
					ordered_liege_or_above = {
						order_by = highest_held_title_tier
						limit = {
							NOR = {
								is_liege_or_above_of = scope:actor
								this = scope:actor
							}
						}
						save_scope_as = recipient
					}
				}
			}
			#You are not in the same realm, go with top_liege
			else = {
				scope:recipient.top_liege = {
					save_scope_as = recipient
				}
			}
		}
	}

	is_shown = {
		scope:recipient = {
			is_ruler = yes
			faith = scope:actor.faith
			primary_title.tier > tier_barony
			any_sub_realm_title = {
				is_landless_type_title = no
				OR = {
					any_claimant = {
						this = scope:actor
					}
					any_this_title_or_de_jure_above = {
						holder ?= scope:actor
					}
				}
			}
			NOT = { target_is_liege_or_above = scope:actor }
			NOR = {
				this = scope:actor
				scope:recipient.religious_head_or_challenger ?= scope:recipient
			}
		}
		scope:actor = {
			NOT = {
				is_at_war_with = scope:recipient
			}
			OR = {
				any_claim = {
					exists = holder
				}
				any_held_title = {
					any_in_de_jure_hierarchy = {
						holder ?= {
							NOR = {
								this = scope:actor
								any_liege_or_above = {
									this = scope:actor
								}
							}
						}
						exists = holder
					}
				}
			}
		}
	}

	populate_recipient_list = {
		scope:recipient.faith = {
			organization = {
				every_organization_member = {
					limit = { claim_valid_faith_subordinate_trigger = yes }
					add_to_list = characters
				}
			}
			if = {
				limit = {
					religious_head ?= {
						clergy_claims_hof_trigger = yes
					}
				}
				religious_head = {
					add_to_list = characters
				}
			}
		}
		scope:recipient = {
			if = {
				limit = {
					religious_head_or_challenger ?= {
						clergy_claims_hof_trigger = yes
					}
				}
				religious_head_or_challenger = {
					add_to_list = characters
				}
			}
		}
	}
	has_valid_target_showing_failures_only = {
		scope:actor = {
			custom_tooltip = {
				text = clergy_land_transfer_strong_claim_tt
				OR = {
					has_strong_claim_on = scope:target
					any_held_title = {
						is_de_jure_liege_or_above_target = scope:target
					}
				}
			}
		}
	}
	can_be_picked_title = {
		scope:target = {
			tier >= tier_county
			is_landless_type_title = no
		}
		scope:actor = {
			custom_tooltip = {
				text = clergy_land_transfer_strong_claim_tt
				OR = {
					has_strong_claim_on = scope:target
					any_held_title = {
						is_de_jure_liege_or_above_target = scope:target
					}
				}
			}
			NOT = { has_title = scope:target }
		}
		trigger_if = {
			limit = {
				scope:secondary_recipient ?= {
					NOT = {
						this = scope:actor.religious_head_or_challenger
					}
				}
			}
			custom_tooltip = {
				text = clergy_land_transfer_hof_only_tt
				scope:target = { tier < tier_kingdom }
			}
		}
		#Don't destroy dukes+ by taking their only counties. I'm onto you, tricky players
		trigger_if = {
			limit = {
				scope:recipient = {
					highest_held_title_tier >= tier_duchy
					NOT = {
						any_held_title = {
							count >= 2
							tier = tier_county
						}
					}
				}
			}
			custom_tooltip = {
				text = clergy_transfer_no_capital_county_tt
				scope:target = {
					NOT = {
						this = scope:recipient.capital_county
					}
				}
			}
		}
		custom_tooltip = {
			text = clergy_land_transfer_theocratic_ecclesiastical_tt
			scope:target.holder ?= {
				NOR = {
					government_has_flag = government_is_ecclesiastical
					government_has_flag = government_is_theocracy
				}
			}
		}
	}
	is_valid_showing_failures_only = {
		scope:actor = {
			trigger_if = {
				limit = {
					NOT = {
						government_has_flag = government_is_theocracy
					}
				}
				has_theological_agent_puppet_trigger = yes
			}
			piety_level >= 2
			trigger_if = {
				limit = {
					highest_held_title_tier >= tier_kingdom
				}
				legitimacy_level >= 4
			}
			trigger_else = {
				legitimacy_level >= 3
			}
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				at_war = no
				travel = no
				activity = no
			}
			
			NOT = { has_trait = excommunicated }
			custom_tooltip = {
				text = above_expected_legitimacy_tt
				any_vassal = {
					count = all
					trigger_if = {
						limit = {
							is_ai = yes
						}
						scope:actor = {
							meets_legitimacy_expectation_of = prev
						}
					}
				}
			}
		}
		scope:recipient = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
			}
			is_at_war = no
			highest_held_title_tier >= tier_county
			NOR = {
				has_strong_hook = scope:actor
				has_trait = greatest_of_khans
				has_trait = conqueror
			}
			#Head of faith is checked first because searching the organization is far more expensive
			trigger_if = {
				limit = {
					NAND = {
						scope:actor.faith = { has_doctrine_parameter = spiritual_head_of_faith }
						OR = {
							NOT = { exists = scope:recipient.religious_head_or_challenger }
							scope:recipient.religious_head_or_challenger ?= { clergy_claims_hof_trigger = yes }
						}
					}
					NOT = {
						scope:actor.faith = {
							organization = {
								any_organization_member = {
									claim_valid_faith_subordinate_trigger = yes
								}
							}
						}
					}
				}
				#Neither route is open at this point, so the two below only report which one is missing
				custom_tooltip = {
					text = responsible_cleric_tt
					scope:actor.faith = { has_doctrine_parameter = spiritual_head_of_faith }
				}
				trigger_if = {
					limit = {
						exists = scope:recipient.religious_head_or_challenger
					}
					custom_tooltip = {
						text = clergy_claim_hof_available_tt
						scope:recipient.religious_head_or_challenger = {
							clergy_claims_hof_trigger = yes
						}
					}
				}
			}
			custom_tooltip = {
				text = clergy_land_transfer_any_strong_claim_tt
				any_sub_realm_title = {
					tier > tier_barony
					OR = {
						any_claimant = {
							this = scope:actor
							has_strong_claim_on = prev
						}
						any_this_title_or_de_jure_above = {
							holder ?= scope:actor
						}
					}
				}
			}
		}
		custom_tooltip = {
			text = clergy_transfer_no_hof_title_tt
			NOT = {
				scope:recipient ?= {
					any_held_title = {
						is_head_of_faith = yes
					}
				}
			}
		}
		trigger_if = { # Can't buy claims on noble families
			limit = {
				scope:target ?= { is_noble_family_title = yes }
			}
			custom_description = {
				text = buy_claim_no_noble_family_titles
				always = no
			}
		}
		trigger_if = { # Can't buy claims on landless adventurer titles
			limit = {
				scope:target ?= { has_variable = adventurer_creation_reason }
			}
			custom_description = {
				text = buy_claim_no_landless_adventurer_title
				always = no
			}
		}
		tgp_blocked_action_against_tenno_trigger = {
			ACTOR = scope:actor
			TARGET = scope:recipient
		}
		pam_not_promised_pilgrimage_trigger = { ACTOR = scope:actor }
		#Only transfer player vassals, never take their titles away
		trigger_if = {
			limit = {
				scope:target ?= {
					holder ?= {
						NOT = {
							this = scope:recipient
						}
					}
					OR = {
						NOT = {
							this = holder.primary_title
						}
						tier >= scope:actor.highest_held_title_tier
					}
				}
			}
			scope:target.holder = {
				is_ai = yes
			}
		}

		#MUST BE ABLE TO CONVINCE RECIPIENT
		custom_tooltip = {
			text = pam_negotiate_land_possible_acceptance_tt
			scope:actor = {
				OR = {
					#Player recipient always a maybe
					pam_instant_negotiate_land_success_trigger = yes
					pam_forced_negotiate_land_success_trigger = yes
					pam_possible_negotiate_land_success_trigger = yes
				}
			}
		}
		#Don't destroy dukes+ by taking their only counties. I'm onto you, tricky players
		trigger_if = {
			limit = {
				exists = scope:target
				scope:recipient = {
					highest_held_title_tier >= tier_duchy
					NOT = {
						any_held_title = {
							count >= 2
							tier = tier_county
						}
					}
				}
			}
			custom_tooltip = {
				text = clergy_transfer_no_capital_county_tt
				scope:target = {
					NOT = {
						this = scope:recipient.capital_county
					}
				}
			}
		}
		custom_tooltip = {
			text = clergy_land_transfer_theocratic_ecclesiastical_recipient_tt
			scope:recipient = {
				NOR = {
					government_has_flag = government_is_ecclesiastical
					government_has_flag = government_is_theocracy
				}
			}
		}
		#For AI high-level scholars and multiplayer - block interaction here
		trigger_if = {
			limit = {
				OR = {
					scope:recipient = {
						is_ai = yes
					}
					AND = {
						scope:actor = { is_ai = no }
						scope:recipient = { is_ai = no }
					}
				}
			}
			custom_tooltip = {
				text = clergy_land_transfer_ai_scholar_tt
				NOT = {
					scope:recipient = {
						has_trait = lifestyle_scholar
						has_trait_xp = {
							trait = lifestyle_scholar
							value >= 60
						}
					}
				}
			}
		}
	}

	on_send = {
	}

	on_accept = {
		if = {
			limit = {
				scope:secondary_recipient = {
					is_ai = no
				}
			}
			#Player clergy can decide whether to grant claim
			scope:secondary_recipient = {
				trigger_event = {
					id = pam_interactions_events.0033
					days = { 2 5 }
				}
			}
		}
		else = {
			#Can do interaction option effects and such immediately, don't have to wait for player priest's acceptance
			scope:actor = {
				#Hidden bc it needs to be always shown, but only here actually done right away
				hidden_effect = { ecclesiastic_transfer_land_interaction_immediate_effect = yes }
			}
			scope:recipient = {
				#Event where recipient is informed and then actor is informed
				trigger_event = {
					id = pam_interactions_events.0032
					days = { 2 5 }
				}
			}
		}
		#Is the recipient going to refuse?
		#No, he will instantly agree
		scope:actor = {
			#Hard to believe... but all the below is just tooltips
			show_as_tooltip = {
				if = {
					limit = {
						pam_instant_negotiate_land_success_trigger = yes
					}
					ecclesiastic_transfer_land_interaction_immediate_effect = yes
					custom_tooltip = pam_clergy_land_instant_success_tt
					if = {
						limit = {
							scope:recipient = {
								piety_level <= 0
								legitimacy_level <= 0
							}
						}
						scope:recipient = { custom_tooltip = clergy_transfer_instant_accept_piety_legitimacy_tt }
					}
					else_if = {
						limit = {
							exists = scope:secondary_recipient
							pam_negotiate_land_instant_pope_hook_trigger = yes
						}
						scope:recipient = { custom_tooltip = clergy_transfer_instant_accept_popes_demands_tt }
					}
					else = {
						scope:recipient = { custom_tooltip = clergy_transfer_instant_accept_terror_tt }
					}
					#You straight-up get the stuff!
					ecclesiastic_transfer_land_interaction_transfer_effect = yes
				}
				#you can - maybe or definitely - get him to agree by investing more
				else = {
					ecclesiastic_transfer_land_interaction_immediate_effect = yes
					pam_available_negotiation_methods_tooltip_effect = yes
					#Show effects.. if you succeed
					custom_tooltip = clergy_land_if_accepted_tt
					ecclesiastic_transfer_land_interaction_transfer_effect = yes
					pam_negotiate_land_possible_refusal_notificaton_effect = yes
				}
			}
		}
	}

	on_decline = {
		scope:actor = {
			trigger_event = pam_interactions_events.0031
		}
	}

	cost = {
		piety = {
			add = {
				value = major_piety_value
				if = {
					limit = {
						exists = scope:target
					}
					multiply = {
						value = scope:target.tier
						subtract = 1
					}
				}
				if = {
					limit = {
						exists = scope:target
						scope:target.tier = tier_kingdom
					}
					scope:target = {
						every_de_jure_county = {
							add = 2
						}
					}
				}
				if = {
					limit = {
						exists = scope:target
						scope:target.tier >= tier_empire
					}
					scope:target = {
						every_de_jure_county = {
							add = 3
						}
					}
				}
			}
			multiply = pam_peace_of_god_clergy_peacemaking_cost_mult_value
			round_to = 5
		}
	}

	auto_accept = {
		OR = {
			#Player recipients auto-accept so they cannot shut down the popup
			scope:recipient = {
				is_ai = no
			}
			AND = {
				exists = scope:secondary_recipient
				custom_description = {
					text = "spending_hook"
					subject = scope:actor
					object = scope:secondary_recipient
					scope:use_hook = yes
					scope:actor = { has_strong_hook = scope:secondary_recipient }
				}
			}
		}
		
	}

	ai_accept = {
		base = -50

		modifier = { # Peace of God: better the Church move a border than an army
			scope:secondary_recipient.rite ?= {
				rite_has_parameter = tenet_peace_of_god_clergy_peacemaking
			}
			add = 40
			desc = pam_peace_of_god_clergy_peacemaking_accept_reason
		}
		modifier = {
			scope:actor = {
				legitimacy_level >= 5
			}
			add = 20
			desc = HIGH_LEGITIMACY_REASON
		}
		#Your gender is scorned by their faith
		modifier = {
			OR = {
				AND = {
					scope:actor = {
						is_female = yes
					}
					scope:recipient = {
						is_female = no
						rite = {
							rite_has_parameter = male_dominated_law
						}
					}
				}
				AND = {
					scope:actor = {
						is_male = yes
					}
					scope:recipient = {
						is_male = no
						rite = {
							rite_has_parameter = female_dominated_law
						}
					}
				}
			}
			add = -20
			desc = NON_DOMINANT_GENDER_REASON
		}
		# Weak hook: extra points
		modifier = {
			scope:use_hook = yes
			add = 200
			scope:actor = { NOT = { has_strong_hook = scope:recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}
		#Malus to king+ trying to gather more king+ titles without increasing their tier
		modifier = {
			exists = scope:target
			scope:target.tier >= tier_kingdom
			scope:actor = {
				highest_held_title_tier >= tier_kingdom
				highest_held_title_tier >= scope:target.tier
			}
			desc = KING_PLUS_TARGETING_KINGDOM_REASON
			add = -200
		}
		modifier = {
			exists = scope:target
			scope:target = { this = scope:recipient.primary_title }
			desc = CLERGY_LAND_TRANSFER_PRIMARY_TITLE_REASON
			add = -100
		}

		#Acceptance modifiers for all these ask the clergy for stuff interactions
		general_secular_to_ecclesiastic_acceptance_secondary_recipient_modifier = yes

		#Acceptance modifiers related to clergy's relation to target title and its possible holders
		title_acquisition_clerical_acceptance_secondary_recipient_modifier = yes

		#Interaction options
		modifier = {
			add = {
				value = 25
				multiply = scope:actor.highest_held_title_tier
			}
			scope:offer_hook = yes
			desc = OFFER_STRONG_HOOK_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 25
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:actor.medium_gold_value < scope:recipient.miniscule_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 50
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:actor.medium_gold_value < scope:recipient.medium_gold_value
			scope:actor.medium_gold_value >= scope:recipient.miniscule_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 75
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:actor.medium_gold_value >= scope:recipient.medium_gold_value
			scope:actor.medium_gold_value < scope:recipient.massive_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 100
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:actor.medium_gold_value >= scope:recipient.massive_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			exists = scope:secondary_recipient
			add = {
				value = 30
				#Modify value by how scary actor is. Are they higher tier than recipient? Are they neighbors?
				if = {
					limit = {
						scope:actor.highest_held_title_tier > scope:secondary_recipient.highest_held_title_tier
					}
					add = {
						value = scope:actor.highest_held_title_tier
						subtract = scope:secondary_recipient.highest_held_title_tier
						multiply = 20
					}
				}
				else_if = {
					limit = {
						scope:actor.highest_held_title_tier < scope:secondary_recipient.highest_held_title_tier_minus_one
					}
					add = -25
				}
				else_if = {
					limit = {
						scope:actor.highest_held_title_tier < scope:secondary_recipient.highest_held_title_tier
					}
					add = -10
				}
				if = {
					limit = {
						scope:actor = {
							OR = {
								is_liege_or_above_of = scope:secondary_recipient
								scope:secondary_recipient ?= {
									any_held_title = {
										is_neighbor_to_realm = scope:actor
									}
								}
								scope:secondary_recipient.capital_county.holder ?= {
									OR = {
										this = scope:actor
										this = scope:recipient
										any_liege_or_above = {
											this = scope:actor
										}
									}
								}
							}
						}
					}
					multiply = 2
				}
				else_if = {
					limit = {
						OR = {
							scope:actor.liege ?= scope:secondary_recipient.liege
							scope:recipient = {
								is_liege_or_above_of = scope:secondary_recipient
							}
						}
					}
					multiply = 1.5
				}
			}
			scope:threaten_priest = yes
			desc = THREATEN_PRIEST_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = pam_offer_pilgrimage_acceptance_value
			scope:offer_pilgrimage = yes
			desc = OFFER_PILGRIMAGE_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 25
				if = {
					limit = {
						scope:actor = {
							highest_held_title_tier >= tier_duchy
						}
					}
					add = 25
				}
				if = {
					limit = {
						scope:target = {
							tier < scope:actor.highest_held_title_tier
						}
					}
					add = 40
				}
				if = {
					limit = {
						scope:target = {
							tier = scope:actor.highest_held_title_tier
						}
					}
					add = 25
				}
				if = {
					limit = {
						scope:actor = {
							OR = {
								has_trait = celibate
								has_trait = eunuch
							}
						}
					}
					multiply = 2
				}
				if = {
					limit = {
						NOT = {
							scope:actor = {
								any_child = {
									scope:actor.primary_title = {
										place_in_line_of_succession = {
											target = prev
											value <= 3
										}
									}
								}
							}
						}
					}
					multiply = 4
				}
				if = {
					limit = {
						scope:actor = {
							age < 50
							age >= 40
						}
					}
					multiply = 0.75
				}
				if = {
					limit = {
						scope:actor = {
							age < 40
							age >= 30
						}
					}
					multiply = 0.5
				}
				if = {
					limit = {
						scope:actor = {
							OR = {
								any_child = {
									count = 2
									scope:actor.primary_title = {
										place_in_line_of_succession = {
											target = prev
											value <= 3
										}
									}
								}
								age < 30
							}
						}
					}
					multiply = 0.25
				}
				if = {
					limit = {
						scope:actor = {
							any_child = {
								count >= 3
								scope:actor.primary_title = {
									place_in_line_of_succession = {
										target = prev
										value <= 3
									}
								}
							}
						}
					}
					multiply = 0.1
				}
				if = {
					limit = {
						scope:actor = {
							is_female = yes
							OR = {
								AND = {
									is_married = yes
									age > 30
									matrilinear_marriage = no
								}
								age >= 40
							}
							any_child = {
								count <= 0
							}
						}
					}
					multiply = 1.5
				}
				min = 5
			}
			scope:promise_church_succession = yes
			desc = OFFER_CHURCH_SUCCESSION_OPTION_REASON
		}


		#Cleric hesitating because of comparison to target's holder
		modifier = {
			exists = scope:target.holder
			scope:secondary_recipient ?= { save_temporary_scope_as = cleric }
			scope:recipient = { save_temporary_scope_as = owner }
			clerical_hesitation_from_target_holder_value != 0
			desc = RECIPIENTS_ESTIMATION_OF_TARGET_HOLDER_PIETY_REASON
			add = {
				value = clerical_hesitation_from_target_holder_value
				multiply = -20
			}
		}
		modifier = {
			scope:secondary_recipient ?= { save_temporary_scope_as = cleric }
			scope:recipient = { save_temporary_scope_as = owner }
			scope:recipient = { is_independent_ruler = no }
			scope:actor = { is_independent_ruler = no }
			scope:recipient.top_liege ?= scope:actor.top_liege
			NOR = {
				scope:actor.liege = scope:recipient.liege
				scope:recipient.liege = scope:actor
				scope:actor.top_liege = scope:recipient
			}
			clerical_hesitation_from_potential_defender_value != 0
			desc = RECIPIENTS_ESTIMATION_OF_TARGET_LIEGE_PIETY_REASON
			add = {
				value = clerical_hesitation_from_potential_defender_value
				multiply = -20
			}

		}
		modifier = {
			scope:secondary_recipient ?= { save_temporary_scope_as = cleric }
			scope:recipient = { save_temporary_scope_as = owner }
			scope:recipient = {
				is_independent_ruler = no
				NOT = {
					top_liege = scope:actor.top_liege
				}
			}
			clerical_hesitation_from_potential_defender_value != 0
			desc = RECIPIENTS_ESTIMATION_OF_TARGET_TOP_LIEGE_PIETY_REASON
			add = {
				value = clerical_hesitation_from_potential_defender_value
				multiply = -20
			}

		}
		modifier = {
			exists = scope:secondary_recipient
			scope:secondary_recipient ?= { save_temporary_scope_as = cleric }
			scope:recipient = {
				save_temporary_scope_as = owner
			}
			scope:target ?= {
				de_jure_liege ?= {
					exists = holder
					NOR = {
						holder = scope:secondary_recipient
						holder = scope:actor
						holder = scope:recipient
					}
				}
			}
			clerical_hesitation_from_potential_defender_value != 0
			desc = RECIPIENTS_ESTIMATION_OF_TARGET_DE_JURE_LIEGE_PIETY_REASON
			add = {
				value = clerical_hesitation_from_potential_defender_value
				multiply = -20
			}
		}

		#Have the Sanctioned Loopholes perk
		modifier = {
			scope:actor = { has_perk = sanctioned_loopholes_perk }
			desc = SANCTIONED_LOOPHOLES_REASON
			add = 200
		}

		#Christian situation
		modifier = {
			situation:the_christian_church ?= {
				any_participant_group = { # Both characters are involved in the situation
					any_situation_group_participant = {
						this = scope:actor
					}
					trigger_if = {
						limit = { scope:recipient = { is_ruler = yes } }
						any_situation_group_participant = {
							this = scope:recipient
						}
					}
				}
				has_situation_top_phase_parameter = claim_seeking_acceptance_bonus
			}
			add = 50
			desc = claim_seeking_acceptance_bonus_desc
		}
		modifier = {
			exists = scope:target
			scope:actor = {
				has_claim_on = scope:target
				any_held_title = {
					is_de_jure_liege_or_above_target = scope:target
				}
			}
			add = {
				value = 60
				if = {
					limit = {
						scope:actor = {
							has_strong_claim_on = scope:target
						}
					}
					add = 40
				}
			}
			desc = clergy_land_transfer_claims_de_jure_reason
		}
	}

	send_option = {
		is_shown = {
			exists = scope:secondary_recipient
			scope:secondary_recipient != scope:actor
		}
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:secondary_recipient
			}
			trigger_if = {
				limit = {
					scope:secondary_recipient = {
						is_ai = no
					}
				}
				scope:actor = { is_ai = no }
			}
		}
		flag = use_hook
		localization = EDUCATION_HOOK_CLERGY
	}

	#You promise the church could inherit this title if it is ever without heirs
	send_option = {
		is_shown = {
			scope:actor = {
				is_ai = no
				highest_held_title_tier <= tier_duchy
				primary_title = {
					NOR = {
						has_title_law_flag = advanced_succession_law
						has_title_law_flag = elective_succession_law
					}
				}
				NOR = {
					exists = fallback_succession_title
					exists = fallback_succession_character
				}
			}
		}
		flag = promise_church_succession
		localization = PROMISE_CHURCH_SUCCESSION_OPTION
	}

	send_option = {
		is_valid = {
			scope:actor = {
				trigger_if = {
					limit = {
						scope:actor = {
							is_ai = yes
						}
					}
					short_term_gold >= massive_gold_value
				}
				trigger_else = {
					gold >= major_gold_value
				}
			}
		}
		flag = donate_faith
		localization = DONATE_TO_THE_FAITH_INTERACTION_OPTION
	}

	send_option = {
		is_valid = {
			exists = scope:secondary_recipient
			scope:actor = {
				dread >= medium_dread_value
			}
			scope:actor = {
				is_ai = no
			}
		}
		flag = threaten_priest
		localization = THREATEN_PRIEST_INTERACTION_OPTION_CLERGY
	}

	send_option = {
		is_valid = {
			NOT = {
				scope:secondary_recipient ?= {
					has_strong_hook = scope:actor
				}
			}
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				always = no
			}
		}
		flag = offer_hook
		localization = OFFER_STRONG_HOOK_INTERACTION_OPTION_CLERGY
	}

	send_option = {
		is_shown = {
			pam_offer_pilgrimage_option_shown_trigger = { ACTOR = scope:actor }
		}
		is_valid = {
			pam_offer_pilgrimage_option_valid_trigger = { ACTOR = scope:actor }
		}
		flag = offer_pilgrimage
		localization = OFFER_PILGRIMAGE_INTERACTION_OPTION_CLERGY
	}

	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}

	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = peer_vassals
		ai_recipients = liege
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 120
		duchy = 36
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = scope:actor.ai_greed
		}

		modifier = {
			add = scope:target.tier
		}

		modifier = {
			add = 500
			has_variable = conqueror
			NOR = {
				has_relation_friend = scope:recipient
				has_relation_lover = scope:recipient
			}
		}

		modifier = {
			add = -100
			scope:actor = {
				OR = {
					has_relation_friend = scope:recipient
					has_relation_lover = scope:recipient
					opinion = {
						target = scope:recipient
						value >= high_positive_opinion
					}
				}
			}
		}

		#Wants titles that should rightfully be yours
		modifier = {
			scope:target = {
				de_jure_liege ?= {
					holder ?= scope:actor
				}
			}
			add = 10
		}
		modifier = {
			scope:target = {
				OR = {
					any_direct_de_jure_vassal_title = {
						holder ?= scope:actor
					}
					any_de_jure_county = {
						any_neighboring_county = {
							OR = {
								holder = scope:actor
								holder = {
									any_liege_or_above = {
										this = scope:actor
									}
								}
							}
						}
					}
				}
			}
			add = 10
		}
		modifier = {
			scope:target = {
				tier >= scope:actor.highest_held_title_tier
			}
			factor = 2
		}
		modifier = {
			scope:secondary_recipient = { save_temporary_scope_as = cleric }
			scope:recipient = { save_temporary_scope_as = owner }
			clerical_hesitation_from_target_holder_value != 0
			add = {
				value = clerical_hesitation_from_target_holder_value
				multiply = 5
			}
		}
		modifier = {
			scope:actor = {
				has_dread_level_towards = {
					target = scope:recipient
					level >= 1
				}
			}
			factor = 0.25
		}
		modifier = {
			scope:actor = {
				has_dread_level_towards = {
					target = scope:recipient
					level >= 2
				}
			}
			factor = 0
		}
		modifier = {
			scope:secondary_recipient ?= {
				this = scope:actor.religious_head
			}
			scope:target.tier < tier_duchy
			factor = 0
		}
		modifier = {
			factor = 0
			NOT = {
				scope:target = {
					is_neighbor_to_realm = scope:actor
				}
			}
		}
		#Don't bother player priests unless you are worthy
		modifier = {
			NOT = { pam_should_bother_clergy_interaction_trigger = { PRIEST = scope:secondary_recipient } }
			factor = 0
		}
		#Less likely to attempt unless they can force it through
		modifier = {
			scope:actor = {
				pam_forced_negotiate_land_success_trigger = no
			}
			factor = 0.5
		}
		#AI should bother player less
		modifier = {
			scope:recipient = {
				is_ai = no
			}
			factor = 0.5
		}
		modifier = {
			factor = {
				value = 0.6
				#Increase reduction based on title tier given away
				if = {
					limit = {
						scope:recipient.var:clergy_land_granted >= 3
					}
					add = -0.2
				}
				if = {
					limit = {
						scope:recipient.var:clergy_land_granted >= 4
					}
					add = -0.2
				}
				if = {
					limit = {
						scope:recipient.var:clergy_land_granted >= 5
					}
					add = -0.1
				}
				if = {
					limit = {
						scope:recipient.var:clergy_land_granted >= 6
					}
					add = -0.05
				}
			}
			scope:recipient = {
				has_variable = clergy_land_granted
			}
		}
		modifier = {
			factor = 0
			exists = scope:secondary_recipient
			#AI will auto-accept when targeting players, so detailed factors are in here
			pam_clergy_title_interaction_player_recipient_auto_accept_trigger = yes
		}
	}
}

# Create a New Ecclesiastical Title as HoF (player only - we'll make the ai use the "request" ones)
create_new_ecclesiastical_title_interaction = {
	category = interaction_category_religion
	icon = request_clerical_title_creation
	interface_priority = 45
	common_interaction = yes

	use_diplomatic_range = yes
	ai_maybe = no
	popup_on_receive = yes

	desc = create_new_ecclesiastical_title_interaction_desc
	target_type = title
	target_filter = domain_titles
	target_source = recipient
	show_all_targets = no

	# Recipient's court chaplain as the default new title holder
	redirect = {
		scope:recipient = {
			# A character may hold only one clerical region, so an existing archbishop cannot default here
			cp:councillor_court_chaplain ?= {
				if = {
					limit = {
						faith = scope:recipient.faith
						NOT = { any_held_title = { has_clerical_region = yes } }
					}
					save_scope_as = secondary_recipient
				}
			}
		}
	}

	# Recipient's court chaplain, then eligible AI courtiers from either the recipient or the actor (HoF) as candidate holders
	populate_recipient_list = {
		scope:recipient = {
			cp:councillor_court_chaplain ?= {
				if = {
					limit = {
						faith = scope:recipient.faith
						NOT = { any_held_title = { has_clerical_region = yes } }
					}
					add_to_list = characters
				}
			}
			every_courtier = {
				limit = {
					is_ai = yes
					NOT = { any_held_title = { has_clerical_region = yes } }
					can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
				}
				add_to_list = characters
			}
		}
		scope:actor = {
			every_courtier = {
				limit = {
					is_ai = yes
					NOT = { any_held_title = { has_clerical_region = yes } }
					can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
				}
				add_to_list = characters
			}
		}
	}

	# Clerical region supporting HoF
	is_available = {
		is_ai = no
		pam_is_clerical_title_authority_trigger = yes # HoF, or the Head of Rites when the faith has no HoF
		faith ?= { has_doctrine_parameter = has_clerical_regions }
		has_pam_dlc_trigger = yes
		is_adult = yes
	}

	# Same-faith duke-or-above holding a title whose de jure capital is not yet in a clerical region
	# We do not require the recipient's own capital, so a seated ruler can still found a see elsewhere
	is_shown = {
		scope:recipient = {
			is_ruler = yes
			faith ?= scope:actor.faith
			NOT = { this = scope:actor }
			any_held_title = {
				tier >= tier_duchy
				is_landless_type_title = no
				title_capital_county ?= {
					NOT = { exists = clerical_region_title }
					OR = {
						holder ?= scope:recipient
						holder ?= {
							any_liege_or_above = {
								this = scope:recipient
							}
						}
					}
				}
			}
		}
	}

	# At least one eligible clergy holder exists; at least one eligible kingdom title can be picked
	is_valid_showing_failures_only = {
		scope:actor = {
			is_imprisoned = no
			is_at_war = no
			is_incapable = no
		}
		scope:recipient = {
			is_imprisoned = no
			is_adult = yes
			pam_actor_is_clerical_title_authority_of_this_trigger = yes
		}
		custom_tooltip = {
			text = create_new_ecclesiastical_title_no_eligible_kingdom_tt
			scope:recipient = {
				any_held_title = {
					pam_valid_new_clerical_region_anchor_trigger = { PETITIONER = scope:recipient }
				}
			}
		}
		custom_tooltip = {
			text = create_new_ecclesiastical_title_no_eligible_holder_tt
			OR = {
				scope:recipient = {
					OR = {
						any_courtier = {
							can_be_court_chaplain_trigger = { COURT_OWNER = scope:recipient }
						}
						cp:councillor_court_chaplain ?= {
							faith = scope:recipient.faith
							NOT = { any_held_title = { has_clerical_region = yes } }
						}
					}
				}
				any_courtier = {
					can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
				}
			}
		}
	}

	has_valid_target_showing_failures_only = {
		custom_tooltip = {
			text = pam_new_clerical_region_invalid_anchor_tt
			scope:target ?= {
				pam_valid_new_clerical_region_anchor_trigger = { PETITIONER = scope:recipient }
			}
		}
	}

	can_be_picked_title = {
		scope:target = {
			pam_valid_new_clerical_region_anchor_trigger = { PETITIONER = scope:recipient }
		}
	}

	# Scales with the free Christian de jure counties of the anchor's de jure kingdom, which is what the region takes
	cost = {
		piety = {
			value = pam_new_clerical_region_cost_value
			# A Head of Rites acting for a faith with no Head of Faith pays more
			if = {
				limit = { NOT = { exists = scope:actor.faith.religious_head } }
				multiply = 1.5
			}
		}
	}

	auto_accept = yes

	# Creates the new clerical region title anchored to the chosen kingdom, sets up the new holder as court chaplain, and fires the situation catalyst
	on_accept = {
		pam_create_new_ecclesiastical_title_interaction_effect = yes
	}
}

# Expand an Ecclesiastical Title as HoF (player only - we'll make the ai use the "request" ones)
expand_ecclesiastical_title_interaction = {
	category = interaction_category_religion
	icon = request_clerical_title_expansion
	interface_priority = 45
	common_interaction = no

	use_diplomatic_range = yes
	ai_maybe = no
	popup_on_receive = yes

	desc = expand_ecclesiastical_title_interaction_desc
	target_type = title
	target_filter = clerical_region_adjacent_duchies
	target_source = recipient
	show_all_targets = no

	# Clerical region supporting HoF
	is_available = {
		is_ai = no
		pam_is_clerical_title_authority_trigger = yes # HoF, or the Head of Rites when the faith has no HoF
		faith ?= { has_doctrine_parameter = has_clerical_regions }
		has_pam_dlc_trigger = yes
		is_adult = yes
	}

	cooldown_against_recipient = { years = 2 }

	# Same-faith ecclesiastical rulers who hold a clerical region with at least one county bordering uncovered land; also the HoF on themselves
	is_shown = {
		scope:recipient = {
			is_ruler = yes
			faith ?= scope:actor.faith
			pam_government_is_religious_playable_trigger = yes
			# Picker only lists duchies around the region at the recipient's capital
			pam_acting_clerical_region_trigger = { ARCHBISHOP = this }
			pam_actor_is_clerical_title_authority_of_this_trigger = yes
		}
	}

	# At least one adjacent duchy passes the picker criteria
	is_valid_showing_failures_only = {
		scope:actor = {
			is_imprisoned = no
			is_at_war = no
			is_incapable = no
		}
		scope:recipient = {
			is_imprisoned = no
			is_adult = yes
			custom_tooltip = { # Must match can_be_picked_title below
				text = expand_ecclesiastical_title_no_eligible_target_tt
				pam_has_eligible_expand_ecclesiastical_title_target_trigger = yes
			}
		}
	}

	can_be_picked_title = {
		pam_valid_expand_ecclesiastical_title_target_trigger = { TITLE = scope:target ARCHBISHOP = scope:recipient }
	}

	# can_be_picked_title is picker-only and is not rechecked on send
	has_valid_target_showing_failures_only = {
		pam_valid_expand_ecclesiastical_title_target_trigger = { TITLE = scope:target ARCHBISHOP = scope:recipient }
	}

	# Piety scales with the number of de jure counties in the chosen target duchy
	cost = {
		piety = {
			value = pam_new_ecclesiastical_title_cost_value
			# A Head of Rites acting for a faith with no Head of Faith pays more
			if = {
				limit = { NOT = { exists = scope:actor.faith.religious_head } }
				multiply = 1.5
			}
		}
	}

	auto_accept = yes

	# Grows the recipient's clerical region into all de jure counties of the chosen duchy and fires the situation catalyst
	on_accept = {
		pam_expand_ecclesiastical_title_interaction_effect = yes
	}
}

# Split an Ecclesiastical Title as HoF (player only - we'll make the ai use the "request" ones)
split_ecclesiastical_title_interaction = {
	category = interaction_category_religion
	icon = request_clerical_title_split
	interface_priority = 45
	common_interaction = no

	use_diplomatic_range = yes
	ai_maybe = no
	popup_on_receive = yes

	desc = split_ecclesiastical_title_interaction_desc

	# Pre-selects a default secular ruler (secondary_actor) by finding a random eligible county holder or liege in the recipient's clerical region THEN pre-selects their court chaplain as the default new holder (secondary_recipient) if available
	redirect = {
		scope:recipient = {
			random_held_title = {
				limit = {
					has_clerical_region = yes
					is_head_of_faith = no
				}
				random_county_in_clerical_region = {
					limit = {
						OR = {
							holder = {
								pam_potential_secular_clerical_split_ruler_trigger = { RULER = this }
							}
							holder = {
								any_liege_or_above = {
									pam_potential_secular_clerical_split_ruler_trigger = { RULER = this }
								}
							}
						}
					}
					holder = {
						if = {
							limit = {
								pam_potential_secular_clerical_split_ruler_trigger = { RULER = this }
							}
							save_scope_as = secondary_actor
						}
						else = {
							random_liege_or_above = {
								limit = {
									pam_potential_secular_clerical_split_ruler_trigger = { RULER = this }
								}
								save_scope_as = secondary_actor
							}
						}
					}
				}
			}
		}
		if = {
			limit = {
				scope:secondary_actor ?= {
					is_ai = yes
					exists = cp:councillor_court_chaplain
					cp:councillor_court_chaplain.faith = scope:actor.faith
					NOT = { cp:councillor_court_chaplain = scope:recipient }
				}
			}
			scope:secondary_actor = {
				cp:councillor_court_chaplain = {
					save_scope_as = secondary_recipient
				}
			}
		}
	}

	# Lists all eligible duke+ secular rulers whose realm capital lies within the recipient's clerical region, found by county holders and their liege chains
	populate_actor_list = {
		scope:recipient = {
			every_held_title = {
				limit = {
					has_clerical_region = yes
					is_head_of_faith = no
				}
				every_county_in_clerical_region = {
					holder = {
						if = {
							limit = {
								pam_potential_secular_clerical_split_ruler_trigger = { RULER = this }
							}
							add_to_list = characters
						}
						every_liege_or_above = {
							limit = {
								pam_potential_secular_clerical_split_ruler_trigger = { RULER = this }
							}
							add_to_list = characters
						}
					}
				}
			}
		}
	}

	# Lists clergy candidates for the new title: the chosen secular ruler's court chaplain (if eligible), their eligible courtiers, and same-faith ecclesiastical holders/top lieges of counties within the recipient's clerical region - excludes existing clerical region holders
	populate_recipient_list = {
		if = {
			limit = { exists = scope:secondary_actor }
			scope:secondary_actor = {
				if = {
					limit = {
						exists = cp:councillor_court_chaplain
						cp:councillor_court_chaplain.faith = scope:actor.faith
						cp:councillor_court_chaplain != scope:recipient
						NOT = {
							cp:councillor_court_chaplain = {
								any_held_title = { has_clerical_region = yes }
							}
						}
					}
					cp:councillor_court_chaplain = { add_to_list = characters }
				}
				every_courtier = {
					limit = {
						is_ai = yes
						this != scope:recipient
						NOT = { any_held_title = { has_clerical_region = no } }
						can_be_court_chaplain_trigger = { COURT_OWNER = scope:secondary_actor }
					}
					add_to_list = characters
				}
			}
		}
		scope:recipient = {
			primary_title = {
				every_county_in_clerical_region = {
					if = {
						limit = {
							holder = {
								is_alive = yes
								is_ruler = yes
								faith = scope:actor.faith
								pam_government_is_religious_playable_trigger = yes
								this != scope:recipient
								NOT = { any_held_title = { has_clerical_region = yes } }
							}
						}
						holder = {
							add_to_list = characters
						}
					}
					if = {
						limit = {
							holder.top_liege = {
								is_alive = yes
								is_ruler = yes
								faith = scope:actor.faith
								pam_government_is_religious_playable_trigger = yes
								this != scope:recipient
								NOT = { any_held_title = { has_clerical_region = yes } }
							}
							holder != scope:recipient
						}
						holder.top_liege = {
							add_to_list = characters
						}
					}
				}
			}
		}
	}

	# Clerical region supporting HoF
	is_available = {
		is_ai = no
		pam_is_clerical_title_authority_trigger = yes # HoF, or the Head of Rites when the faith has no HoF
		faith ?= { has_doctrine_parameter = has_clerical_regions }
		has_pam_dlc_trigger = yes
		is_adult = yes
	}

	cooldown_against_recipient = { years = 10 }

	is_shown = {
		scope:actor = {
			pam_is_antipope_trigger = no
		}
		scope:recipient = {
			is_ruler = yes
			faith ?= scope:actor.faith
			pam_government_is_religious_playable_trigger = yes
			any_held_title = {
				has_clerical_region = yes
				# The HoF may split their own see; other rulers' head-of-faith titles stay protected
				trigger_if = {
					limit = { scope:recipient != scope:actor }
					is_head_of_faith = no
				}
				any_county_in_clerical_region = {
					OR = {
						holder ?= {
							pam_potential_secular_clerical_split_ruler_trigger = { RULER = this }
						}
						holder ?= {
							any_liege_or_above = {
								pam_potential_secular_clerical_split_ruler_trigger = { RULER = this }
							}
						}
					}
				}
			}
		}
	}

	# A valid secular ruler exists to split from, and that an eligible clergy holder candidate exists
	is_valid_showing_failures_only = {
		scope:actor = {
			is_imprisoned = no
			is_at_war = no
			is_incapable = no
		}
		scope:recipient = {
			is_imprisoned = no
			is_adult = yes
			pam_actor_is_clerical_title_authority_of_this_trigger = yes
		}
		custom_tooltip = {
			text = split_ecclesiastical_title_no_eligible_secular_ruler_tt
			scope:recipient = {
				any_held_title = {
					has_clerical_region = yes
					# Mirror is_shown: the HoF may split their own see, other rulers' head-of-faith titles stay protected
					trigger_if = {
						limit = { scope:recipient != scope:actor }
						is_head_of_faith = no
					}
					any_county_in_clerical_region = {
						OR = {
							holder = {
								pam_valid_secular_clerical_split_ruler_trigger = { RULER = this }
							}
							holder = {
								any_liege_or_above = {
									pam_valid_secular_clerical_split_ruler_trigger = { RULER = this }
								}
							}
						}
					}
				}
			}
			trigger_if = {
				limit = { exists = scope:secondary_actor }
				pam_valid_secular_clerical_split_ruler_trigger = { RULER = scope:secondary_actor }
			}
		}
		custom_tooltip = {
			text = split_ecclesiastical_title_no_eligible_holder_tt
			OR = {
				AND = {
					exists = scope:secondary_actor
					OR = {
						scope:secondary_actor = {
							exists = cp:councillor_court_chaplain
							cp:councillor_court_chaplain.faith = scope:actor.faith
							cp:councillor_court_chaplain != scope:recipient
						}
						scope:secondary_actor = {
							any_courtier = {
								this != scope:recipient
								can_be_court_chaplain_trigger = { COURT_OWNER = scope:secondary_actor }
							}
						}
					scope:recipient = {
						primary_title = {
							any_county_in_clerical_region = {
								holder = {
									is_alive = yes
									is_ruler = yes
									faith = scope:actor.faith
									pam_government_is_religious_playable_trigger = yes
									this != scope:recipient
									NOT = { any_held_title = { has_clerical_region = yes } }
								}
							}
						}
					}
					}
				}
				NOT = { exists = scope:secondary_actor }
			}
		}
	}

	# Piety scales with the number of de jure counties in the chosen secular ruler's primary title
	cost = {
		piety = {
			value = pam_split_ecclesiastical_title_cost_value
			# A Head of Rites acting for a faith with no Head of Faith pays more
			if = {
				limit = { NOT = { exists = scope:actor.faith.religious_head } }
				multiply = 1.5
			}
		}
	}

	auto_accept = yes

	# Splits the secular ruler's land out of the clerical region, creates the new title, grants it to the chosen holder, and fires the situation catalyst
	on_accept = {
		pam_split_ecclesiastical_title_interaction_effect = yes
	}
}

# Merge an Ecclesiastical Title as HoF (player only - we'll make the ai use the "request" ones)
merge_new_ecclesiastical_title_interaction = {
	category = interaction_category_religion
	icon = request_clerical_title_merger
	interface_priority = 45
	common_interaction = no

	use_diplomatic_range = yes
	ai_maybe = no
	popup_on_receive = yes

	desc = merge_new_ecclesiastical_title_interaction_desc
	target_type = title
	target_filter = clerical_region
	show_all_targets = no

	# Clerical region supporting HoF
	is_available = {
		is_ai = no
		pam_is_clerical_title_authority_trigger = yes # HoF, or the Head of Rites when the faith has no HoF
		faith ?= { has_doctrine_parameter = has_clerical_regions }
		has_pam_dlc_trigger = yes
		is_adult = yes
	}

	cooldown_against_recipient = { years = 20 }

	# Same-faith ecclesiastical rulers that border at least one other same-faith clerical region; also the HoF on themselves
	is_shown = {
		scope:recipient = {
			is_ruler = yes
			faith ?= scope:actor.faith
			pam_government_is_religious_playable_trigger = yes
			any_held_title = {
				has_clerical_region = yes
				is_head_of_faith = no
			}
			pam_actor_is_clerical_title_authority_of_this_trigger = yes
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_imprisoned = no
			is_at_war = no
			is_incapable = no
		}
		scope:recipient = {
			is_imprisoned = no
			is_adult = yes
			custom_tooltip = {
				text = merge_new_ecclesiastical_title_cooldown_trigger
				NOT = { exists = capital_province.county.clerical_region_title.var:merge_clerical_region_cooldown }
			}
			# Must be the recipient's own region, because a landed archbishop's capital can sit in another region
			pam_acting_clerical_region_trigger = { ARCHBISHOP = this }
			capital_province.county.clerical_region_title ?= {
				pam_has_adjacent_mergeable_clerical_region_trigger = yes
			}
		}
	}

	can_be_picked_title = {
		pam_acting_clerical_region_trigger = { ARCHBISHOP = scope:recipient }
		pam_potential_merge_clerical_region_title_trigger = {
			TITLE = scope:target
			ABSORBING_TITLE = scope:recipient.capital_province.county.clerical_region_title
		}
	}

	# can_be_picked_title is picker-only and is not rechecked on send
	has_valid_target_showing_failures_only = {
		pam_acting_clerical_region_trigger = { ARCHBISHOP = scope:recipient }
		pam_potential_merge_clerical_region_title_trigger = {
			TITLE = scope:target
			ABSORBING_TITLE = scope:recipient.capital_province.county.clerical_region_title
		}
	}

	# Piety scales with the number of counties in the absorbed clerical region
	cost = {
		piety = {
			value = pam_merge_new_ecclesiastical_title_cost_value
			# A Head of Rites acting for a faith with no Head of Faith pays more
			if = {
				limit = { NOT = { exists = scope:actor.faith.religious_head } }
				multiply = 2
			}
		}
	}

	auto_accept = yes

	# Absorbs all counties of the target clerical region into the recipient's primary title via grow_clerical_region_fromand destroys it
	on_accept = {
		pam_merge_new_ecclesiastical_title_interaction_effect = {
			ABSORBING_TITLE = scope:recipient.capital_province.county.clerical_region_title
			ABSORBED_TITLE = scope:target
			SENDER = scope:actor
		}
	}
}

# Replace a sitting archbishop as HoF: the see and all their lands pass to a chosen candidate (player only - the ai uses grant_ecclesiastical_title_interaction)
replace_ecclesiastical_title_holder_interaction = {
	category = interaction_category_religion
	icon = icon_clergy_move_lands
	interface_priority = 45
	common_interaction = yes

	use_diplomatic_range = yes
	ai_maybe = no
	popup_on_receive = yes

	desc = replace_ecclesiastical_title_holder_interaction_desc
	target_type = title
	target_filter = recipient_domain_titles
	show_all_targets = no

	# Actor's court chaplain as the default replacement; must match their entry in populate_recipient_list below
	redirect = {
		scope:actor = {
			if = {
				limit = {
					cp:councillor_court_chaplain ?= {
						NOT = { any_held_title = { has_clerical_region = yes } }
						can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
						trigger_if = {
							limit = { is_landed = yes }
							capital_county.clerical_region_title.holder ?= scope:recipient
						}
					}
				}
				cp:councillor_court_chaplain ?= {
					save_scope_as = secondary_recipient
				}
			}
		}
	}

	# Landed candidates must be based in the recipient's archdiocese, or their lands would drag the see into a foreign realm
	populate_recipient_list = {
		scope:actor = {
			if = {
				limit = {
					cp:councillor_court_chaplain ?= {
						NOT = { any_held_title = { has_clerical_region = yes } }
						can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
						trigger_if = {
							limit = { is_landed = yes }
							capital_county.clerical_region_title.holder ?= scope:recipient
						}
					}
				}
				cp:councillor_court_chaplain ?= { add_to_list = characters }
			}
			every_courtier = {
				limit = {
					NOT = { any_held_title = { has_clerical_region = yes } }
					can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
				}
				add_to_list = characters
			}
			every_close_family_member = {
				limit = {
					NOT = { any_held_title = { has_clerical_region = yes } }
					can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
					trigger_if = {
						limit = { is_landed = yes }
						capital_county.clerical_region_title.holder ?= scope:recipient
					}
				}
				add_to_list = characters
			}
			every_vassal = {
				limit = {
					NOT = { any_held_title = { has_clerical_region = yes } }
					can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
					has_government = ecclesiastical_government
					trigger_if = {
						limit = { is_landed = yes }
						capital_county.clerical_region_title.holder ?= scope:recipient
					}
				}
				add_to_list = characters
			}
		}
	}

	# Church authority (HoF / Head of Rites), or a liege the faith's Clerical Appointment doctrine empowers
	is_available = {
		faith ?= { has_doctrine_parameter = has_clerical_regions }
		OR = {
			# A secular liege when the doctrine grants rulers the right (Temporal/Revocable, Conditional)
			AND = {
				faith ?= { has_doctrine_parameter = clerical_appointment_ruler_can_replace_ecc }
				government_is_religious_trigger = no
			}
			# A clergy liege under Conditional (which carries both rights)
			AND = {
				faith ?= {
					has_doctrine_parameter = clerical_appointment_hof_can_replace_ecc
					has_doctrine_parameter = clerical_appointment_ruler_can_replace_ecc
				}
				government_is_religious_trigger = yes
			}
			# HoF / Head of Rites - blocked only under Temporal, Revocable (the crown alone holds the right then)
			AND = {
				faith ?= {
					OR = {
						has_doctrine_parameter = clerical_appointment_hof_can_replace_ecc
						NOT = { has_doctrine_parameter = clerical_appointment_ruler_can_replace_ecc }
					}
				}
				pam_is_clerical_title_authority_trigger = yes
			}
		}
		has_pam_dlc_trigger = yes
	}

	cooldown = { years = 10 }

	# Same-faith AI archbishops; the HoF's own see stays protected
	is_shown = {
		scope:recipient = {
			is_ai = yes
			is_ruler = yes
			this != scope:actor
			faith ?= scope:actor.faith
			pam_government_is_religious_playable_trigger = yes
			any_held_title = {
				has_clerical_region = yes
				is_head_of_faith = no
			}
			# A liege acting on the doctrine right (not the HoF / Head of Rites) may only depose their own vassals
			trigger_if = {
				limit = {
					pam_actor_is_clerical_title_authority_of_this_trigger = no
				}
				is_vassal_or_below_of = scope:actor
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_imprisoned = no
			is_at_war = no
			is_incapable = no
		}
		scope:recipient = {
			is_imprisoned = no
			is_adult = yes
		}
		custom_tooltip = {
			text = replace_ecclesiastical_title_holder_antipope_tt
			scope:recipient = { pam_is_antipope_trigger = no }
		}
		pam_not_promised_pilgrimage_trigger = { ACTOR = scope:actor }
		# Players may seat another rite of the faith; the AI keeps its sees on its own rite
		trigger_if = {
			limit = {
				scope:actor = { is_ai = yes }
				exists = scope:secondary_recipient
			}
			scope:secondary_recipient.rite = scope:actor.rite
		}
		custom_tooltip = { # Must match populate_recipient_list above
			text = replace_ecclesiastical_title_holder_no_candidate_tt
			scope:actor = {
				OR = {
					cp:councillor_court_chaplain ?= {
						NOT = { any_held_title = { has_clerical_region = yes } }
						can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
						trigger_if = {
							limit = { is_landed = yes }
							capital_county.clerical_region_title.holder ?= scope:recipient
						}
					}
					any_courtier = {
						NOT = { any_held_title = { has_clerical_region = yes } }
						can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
					}
					any_close_family_member = {
						NOT = { any_held_title = { has_clerical_region = yes } }
						can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
						trigger_if = {
							limit = { is_landed = yes }
							capital_county.clerical_region_title.holder ?= scope:recipient
						}
					}
					any_vassal = {
						has_government = ecclesiastical_government
						NOT = { any_held_title = { has_clerical_region = yes } }
						can_be_court_chaplain_trigger = { COURT_OWNER = scope:actor }
						trigger_if = {
							limit = { is_landed = yes }
							capital_county.clerical_region_title.holder ?= scope:recipient
						}
					}
				}
			}
		}
		trigger_if = {
			limit = {
				scope:recipient = { rite != scope:actor.rite }
			}
			custom_tooltip = {
				text = replace_ecclesiastical_title_holder_learning_tt_hashcollission
				scope:actor.learning > scope:recipient.learning
			}
		}
	}

	can_be_picked_title = {
		scope:target = {
			holder = scope:recipient
			has_clerical_region = yes
			is_head_of_faith = no
		}
	}

			# Deposing a holder doubles the cost; one of another rite costs three times the base, and their head of rite ten times
	cost = {
		piety = {
			value = pam_grant_ecclesiastical_title_cost_value
			# A Head of Rites acting for a faith with no Head of Faith pays more
			if = {
				limit = { NOT = { exists = scope:actor.faith.religious_head } }
				multiply = 1.5
			}
		}
		treasury_or_gold = {
			value = pam_grant_ecclesiastical_title_gold_cost_value
		}
	}

	auto_accept = yes

	on_accept = {
		scope:secondary_recipient = { save_scope_as = pam_new_archbishop }
		scope:recipient = { save_scope_as = pam_old_archbishop }
		pam_grant_ecclesiastical_title_interaction_effect = yes
		# Meddling by a liege (not the HoF / Head of Rites) angers the wider clergy
		if = {
			limit = {
				scope:actor = { pam_is_clerical_title_authority_trigger = no }
			}
			scope:actor = {
				add_character_modifier = {
					modifier = pam_meddled_in_clerical_appointments_modifier
					years = 10
				}
			}
		}
		# Using the Conditional doctrine's right (it carries both replace params) pushes toward the Investiture Crisis
		if = {
			limit = {
				scope:actor = {
					faith = {
						has_doctrine_parameter = clerical_appointment_ruler_can_replace_ecc
						has_doctrine_parameter = clerical_appointment_hof_can_replace_ecc
					}
				}
				situation:the_christian_church ?= {
					situation_top_has_catalyst = catalyst_conditional_appointment_used
				}
			}
			situation:the_christian_church = {
				trigger_situation_catalyst = catalyst_conditional_appointment_used
			}
		}
	}

	ai_targets = {
		ai_recipients = vassals
		ai_recipients = clerical_region_rulers_in_realm
		max = 10
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 48
		kingdom = 24
		empire = 24
		hegemony = 24
	}

	# AI only acts where a Clerical Appointment doctrine grants the right, so the base-game tool stays player-driven
	ai_will_do = {
		base = 0
		# A secular liege installs a loyal candidate over a disloyal bishop (Temporal/Revocable, Conditional)
		modifier = {
			add = 30
			scope:actor = {
				government_is_religious_trigger = no
				faith = { has_doctrine_parameter = clerical_appointment_ruler_can_replace_ecc }
			}
			scope:recipient = {
				opinion = {
					target = scope:actor
					value <= -20
				}
			}
		}
		# The Head of Faith removes disloyal bishops (Spiritual/Revocable, Conditional)
		modifier = {
			add = 40
			scope:actor = {
				religious_head_or_challenger ?= this
				faith = { has_doctrine_parameter = clerical_appointment_hof_can_replace_ecc }
			}
			scope:recipient = {
				opinion = {
					target = scope:actor
					value <= -25
				}
			}
		}
	}
}

# Grant an existing clerical title as HoF: a vacant see, or one taken from its sitting holder together with all their lands
grant_ecclesiastical_title_interaction = {
	category = interaction_category_religion
	icon = icon_clergy_claim_unformed_kingdom
	interface_priority = 45
	common_interaction = no

	use_diplomatic_range = yes
	ai_maybe = no
	popup_on_receive = yes

	desc = grant_ecclesiastical_title_interaction_desc
	notification_text = grant_ecclesiastical_title_interaction_notification
	target_type = title
	target_filter = clerical_region
	show_all_targets = no

	# Clerical region supporting HoF
	is_available = {
		faith ?= { has_doctrine_parameter = has_clerical_regions }
		is_adult = yes
		pam_is_clerical_title_authority_trigger = yes # HoF, or the Head of Rites when the faith has no HoF
		has_pam_dlc_trigger = yes
	}

	cooldown_against_recipient = { years = 5 }

	# We include clergy and any non-ruler the holder could elevate, wider than the clergy organization
	is_shown = {
		scope:recipient = {
			this != scope:actor
			faith ?= scope:actor.faith
			OR = {
				is_clergy = yes
				is_ruler = no
			}
			OR = {
				is_landed = no
				government_has_flag = government_is_theocracy
			}
			NOT = { any_held_title = { has_clerical_region = yes } }
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_physically_able_adult = yes
		}
		scope:recipient = {
			is_physically_able_adult = yes
			NOT = { has_trait = excommunicated }
		}
		custom_tooltip = {
			text = pam_interaction_clerical_gender_tt
			scope:actor.rite = { rite_has_allowed_gender_for_clergy = scope:recipient }
		}
		# A landed cleric elsewhere would drag the see into a foreign realm
		trigger_if = {
			limit = {
				scope:recipient = { is_landed = yes }
			}
			custom_tooltip = {
				text = grant_ecclesiastical_title_landed_recipient_tt
				exists = scope:recipient.capital_county.clerical_region_title
			}
		}
		# Checked here rather than in has_valid_target so cross-rite sees stay visible in the picker instead of being hidden
		trigger_if = {
			limit = {
				scope:target.holder ?= { rite != scope:actor.rite }
			}
			custom_tooltip = {
				text = grant_ecclesiastical_title_learning_tt
				scope:actor.learning > scope:target.holder.learning
			}
		}
	}

	# Vacant same-faith sees, or sees held by an AI archbishop of the actor's faith; landed clerics may only receive the see covering their own capital
	can_be_picked_title = {
		scope:target = {
			has_clerical_region = yes
			is_head_of_faith = no
			# An absorbed region lingers as an empty shell, and granting one mints a landless archbishop
			clerical_region_size > 0
			trigger_if = {
				limit = { exists = holder }
				holder = {
					is_ai = yes
					faith = scope:actor.faith
					this != scope:actor
					this != scope:recipient
					pam_is_antipope_trigger = no
				}
			}
			trigger_else = {
				title_capital_county.holder.faith = scope:actor.faith
			}
			trigger_if = {
				limit = {
					scope:recipient = { is_landed = yes }
				}
				scope:recipient.capital_county.clerical_region_title ?= this
			}
		}
		pam_antipope_may_grant_clerical_region_trigger = { SEE = scope:target }
	}

	# can_be_picked_title only applies in the picker and is out of date until a save and reload
	# The empty-shell filter repeats here for the AI
	has_valid_target_showing_failures_only = {
		custom_tooltip = {
			text = grant_ecclesiastical_title_empty_region_tt
			scope:target ?= { clerical_region_size > 0 }
		}
		custom_tooltip = {
			text = grant_ecclesiastical_title_antipope_obedience_tt
			pam_antipope_may_grant_clerical_region_trigger = { SEE = scope:target }
		}
		trigger_if = {
			limit = { exists = scope:target.holder }
			custom_tooltip = {
				text = grant_ecclesiastical_title_antipope_holder_tt
				scope:target.holder = { pam_is_antipope_trigger = no }
			}
		}
	}

			# Deposing a holder doubles the cost; one of another rite costs three times the base, and their head of rite ten times
	cost = {
		piety = {
			value = pam_grant_ecclesiastical_title_cost_value
			# A Head of Rites acting for a faith with no Head of Faith pays more
			if = {
				limit = { NOT = { exists = scope:actor.faith.religious_head } }
				multiply = 1.5
			}
		}
		treasury_or_gold = {
			value = pam_grant_ecclesiastical_title_gold_cost_value
		}
	}

	auto_accept = {
		scope:recipient = { is_ai = yes }
	}

	on_accept = {
		scope:recipient = { save_scope_as = pam_new_archbishop }
		if = {
			limit = { exists = scope:target.holder }
			scope:target.holder = { save_scope_as = pam_old_archbishop }
		}
		pam_grant_ecclesiastical_title_interaction_effect = yes
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = ecclesiastic_title_refusal_toast_tt
				left_icon = scope:recipient
			}
		}
	}

	ai_accept = {
		base = 100
	}

	ai_targets = {
		ai_recipients = councillors
		ai_recipients = scripted_relations
		ai_recipients = subordinates
	}
	ai_targets = {
		ai_recipients = courtiers
		max = 10
	}
	ai_targets = {
		ai_recipients = family
		max = 5
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 6
		empire = 6
		hegemony = 6
	}

	ai_will_do = {
		base = 0

		# Fill vacant sees
		modifier = {
			add = 1000
			NOT = { exists = scope:target.holder }
		}
		# Depose rivals and openly disgraced archbishops
		modifier = {
			add = 100
			scope:target.holder ?= {
				pam_ai_deposable_cleric_trigger = { HEAD_OF_FAITH = scope:actor }
			}
		}
		# Reform pushes for one rite across every see, ahead of any personal grudge
		modifier = {
			add = 150
			pam_ai_reform_rite_replacement_trigger = yes
		}
		# Never invest someone who would immediately qualify for deposition
		modifier = {
			factor = 0
			scope:recipient = {
				pam_ai_deposable_cleric_trigger = { HEAD_OF_FAITH = scope:actor }
			}
		}
		# Only invest friends, lovers, and clerics of great repute, except when clearing another rite out during Reform
		modifier = {
			factor = 0
			exists = scope:target.holder
			pam_ai_reform_rite_replacement_trigger = no
			scope:recipient = {
				NOR = {
					has_relation_friend = scope:actor
					has_relation_lover = scope:actor
					piety_level >= 2
					AND = {
						learning > scope:target.holder.learning
						learning >= 8
					}
					AND = {
						num_virtuous_traits >= 1
						num_sinful_traits <= 0
					}
				}
			}
		}
	}
}

petition_antipope_indulgences_interaction = {
	category = interaction_category_religion
	icon = petition_antipope_indulgences
	common_interaction = yes

	desc = petition_antipope_indulgences_interaction_desc
	notification_text = RELIGIOUS_HEAD_SEEK_INDULGENCES
	
	ai_targets = {
		ai_recipients = religious_head_challenger
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 36
		duchy = 24
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	is_available = {
		faith = {
			faith_has_sacraments_central_trigger = yes
			OR = {
				has_doctrine_parameter = has_clerical_regions
				has_doctrine = doctrine_spiritual_head
				has_doctrine = doctrine_temporal_head
			}
		}
		rite = {
			NOT = {
				rite_has_parameter = no_seek_indulgences
			}
		}
	}

	is_shown = {
		# Anyone under an antipope or their sponsor petitions that antipope, not the Head of Faith
		scope:actor = { is_following_religious_head_challenger = yes }
		has_pam_dlc_trigger = yes
		scope:actor != scope:recipient
		scope:actor.religious_head_or_challenger ?= scope:recipient
	}

	cooldown = { years = 5 }

	is_valid_showing_failures_only = {
		scope:actor = {
			NOT = {
				is_at_war_with = scope:recipient
			}
			NOT = {
				has_character_modifier = promised_pilgrimage_to_clergy_modifier
			}
			trigger_if = {
				limit = {
					has_trait = kinslayer_3
					trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:kinslayer_3 GENDER_CHARACTER = scope:actor }
				}
				gold >= seek_indulgences_major_criminal_trait_value
			}
			trigger_else_if = {
				limit = {
					OR = {
						AND = {
							has_trait = kinslayer_2
							trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:kinslayer_2 GENDER_CHARACTER = scope:actor }
						}
						AND = {
							has_trait = witch
							trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:witch GENDER_CHARACTER = scope:actor }
						}
						AND = {
							has_trait = deviant
							trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:deviant GENDER_CHARACTER = scope:actor }
						}
						AND = {
							has_trait = sodomite
							trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:sodomite GENDER_CHARACTER = scope:actor }
						}
					}
				}
				gold >= seek_indulgences_medium_criminal_trait_value
			}
			trigger_else_if = {
				limit = {
					OR = {
						AND = {
							has_trait = kinslayer_1
							trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:kinslayer_1 GENDER_CHARACTER = scope:actor }
						}
						AND = {
							has_trait = fornicator
							trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:fornicator GENDER_CHARACTER = scope:actor }
						}
						AND = {
							has_trait = adulterer
							trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:adulterer GENDER_CHARACTER = scope:actor }
						}
					}
				}
				gold >= seek_indulgences_minor_criminal_trait_value
			}
			trigger_else = {
				gold >= seek_indulgences_antipope_buy_piety_value
			}
		}
		scope:recipient = {
			is_alive = yes
			pam_is_antipope_trigger = yes
		}
	}

	# Autoaccept if you are the sponsor
	auto_accept = {
		custom_description = {
			text = petition_antipope_sponsor_auto_accept_tt
			subject = scope:actor
			object = scope:recipient
			scope:recipient = {
				pam_antipope_is_sponsored_by_trigger = { SPONSOR = scope:actor }
			}
		}
	}

	send_options_exclusive = no

	send_option = {
		is_shown = {
			pam_offer_pilgrimage_option_shown_trigger = { ACTOR = scope:actor }
		}
		is_valid = {
			pam_offer_pilgrimage_option_valid_trigger = { ACTOR = scope:actor }
		}
		flag = offer_pilgrimage
		localization = OFFER_PILGRIMAGE_INTERACTION_OPTION
	}

	ai_accept = {
		base = 75

		seek_indulgences_acceptance_modifier = yes

		modifier = {
			add = pam_offer_pilgrimage_acceptance_value
			scope:offer_pilgrimage = yes
			desc = OFFER_PILGRIMAGE_INTERACTION_OPTION_REASON
		}
	}

	ai_min_reply_days = 1
	ai_max_reply_days = 5

	on_accept = {
		seek_indulgences_interaction_effect = yes
		pam_offer_pilgrimage_effect = {
			ACTOR = scope:actor
			CLERIC = scope:recipient
		}
	}
}

petition_antipope_gold_interaction = {
	category = interaction_category_religion
	icon = petition_antipope_gold
	common_interaction = yes

	desc = petition_antipope_gold_interaction_desc
	notification_text = petition_antipope_gold_interaction_notification
	
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_targets = {
		ai_recipients = religious_head_challenger
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 36
		duchy = 24
		kingdom = 6
		empire = 6
		hegemony = 6
	}

	is_shown = {
		# Anyone under an antipope or their sponsor petitions that antipope, not the Head of Faith
		scope:actor = { is_following_religious_head_challenger = yes }
		has_pam_dlc_trigger = yes
		scope:actor != scope:recipient
		scope:actor.religious_head_or_challenger ?= scope:recipient
	}

	cooldown_against_recipient = { years = 3 }

	is_valid_showing_failures_only = {
		scope:actor = {
			NOT = { is_at_war_with = scope:recipient }
			NOT = {
				has_character_modifier = promised_pilgrimage_to_clergy_modifier
			}
		}
		scope:recipient = {
			is_alive = yes
			pam_is_antipope_trigger = yes
			treasury >= medium_treasury_or_gold_value
		}
	}

	# Autoaccept if you are the sponsor
	auto_accept = {
		custom_description = {
			text = petition_antipope_sponsor_auto_accept_tt
			subject = scope:actor
			object = scope:recipient
			scope:recipient = {
				pam_antipope_is_sponsored_by_trigger = { SPONSOR = scope:actor }
			}
		}
	}

	send_options_exclusive = no

	send_option = {
		is_shown = {
			pam_offer_pilgrimage_option_shown_trigger = { ACTOR = scope:actor }
		}
		is_valid = {
			pam_offer_pilgrimage_option_valid_trigger = { ACTOR = scope:actor }
		}
		flag = offer_pilgrimage
		localization = OFFER_PILGRIMAGE_INTERACTION_OPTION
	}

	ai_accept = {
		base = -40

		ask_for_gold_acceptance_modifier = yes

		modifier = {
			add = pam_offer_pilgrimage_acceptance_value
			scope:offer_pilgrimage = yes
			desc = OFFER_PILGRIMAGE_INTERACTION_OPTION_REASON
		}
	}

	ai_min_reply_days = 1
	ai_max_reply_days = 5

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				title = petition_antipope_gold_interaction_title
				right_icon = scope:recipient
				scope:recipient = {
					pay_treasury_or_gold = {
						target = scope:actor
						value = medium_treasury_or_gold_value
					}
				}
			}
		}
		pam_offer_pilgrimage_effect = {
			ACTOR = scope:actor
			CLERIC = scope:recipient
		}
	}
}

#Sponsor a same-faith ruler's kingdom holy war against a hostile-faith ruler
ecclesiastic_incite_holy_war_interaction = {
	category = interaction_category_diplomacy
	icon = minor_religious_war
	interface_priority = 75
	common_interaction = yes
	target_type = title
	target_filter = dejure_titles
	target_source = recipient
	notification_text = ecclesiastic_incite_holy_war_interaction_notification
	greeting = negative
	use_diplomatic_range = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = no
	cooldown_against_recipient = { years = 5 }
	use_diplomatic_range = no

	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			piety >= 750
			piety_level >= 3
			OR = {
				government_has_flag = government_is_ecclesiastical
				this = faith.religious_head
			}
			is_at_war = no
			religion ?= religion:christianity_religion
		}
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			actor_incite_holy_war_shown_trigger = yes
			save_temporary_scope_as = attacker
		}
		are_holy_wars_disabled_by_struggle_conciliation_trigger = no # Disabled against other involved faiths in FP2 Conciliation ending
		has_pam_dlc_trigger = yes
		scope:recipient = {
			is_landed = yes
			top_liege ?= this
			NOT = { faith = scope:puppet_or_actor.faith }
			save_temporary_scope_as = defender
			are_holy_wars_disabled_by_struggle_conciliation_trigger = no # Disabled against other involved faiths in FP2 Conciliation ending
		}
		scope:recipient != scope:puppet_or_actor
	}

	populate_recipient_list = {
		scope:puppet_or_actor = {
			faith = {
				every_faith_ruler = {
					limit = {
						valid_holy_war_incited_attacker_trigger = { RECIPIENT = scope:recipient }
					}
					add_to_list = characters
				}
			}
		}
	}

	can_be_picked_title = {
		scope:target = {
			incite_holy_war_title_can_be_picked_trigger = { RECIPIENT = scope:recipient SECONDARY = scope:secondary_recipient }
		}
	}

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			is_available_quick = {
				adult = yes
				alive = yes
				imprisoned = no
				incapable = no
			}
			
			trigger_if = {
				limit = {
					scope:target ?= {
						tier >= tier_kingdom
					}
				}
				trigger_if = {
					limit = {
						top_participant_group:the_christian_church ?= {
							has_participant_group_parameter = the_christian_church_incite_holy_war_interaction
						}
					}
					custom_tooltip = {
						text = piety_too_low_target_kingdom_special_tt
						piety_level >= 3
					}
				}
				trigger_else = {
					custom_tooltip = {
						text = piety_too_low_target_kingdom_tt
						piety_level >= 4
					}
				}
			}
			trigger_else_if = {
				limit = {
					scope:target ?= {
						tier >= tier_duchy
					}
				}
				trigger_if = {
					limit = {
						top_participant_group:the_christian_church ?= {
							has_participant_group_parameter = the_christian_church_incite_holy_war_interaction
						}
					}
					custom_tooltip = {
						text = piety_too_low_target_duchy_special_tt
						piety_level >= 2
					}
				}
				trigger_else = {
					custom_tooltip = {
						text = piety_too_low_target_duchy_tt
						piety_level >= 3
					}
				}
			}
			trigger_else = {
				trigger_if = {
					limit = {
						top_participant_group:the_christian_church ?= {
							has_participant_group_parameter = the_christian_church_incite_holy_war_interaction
						}
					}
					piety_level >= 1
				}
				trigger_else = {
					piety_level >= 2
				}
			}
			custom_tooltip = {
				text = no_valid_sponsored_holy_war_attacker_tt
				faith = {
					any_faith_ruler = {
						valid_holy_war_incited_attacker_trigger = { RECIPIENT = scope:recipient }
					}
				}
			}
			
			custom_tooltip = {
				text = religious_war_hostility_tt
				faith = {
					faith_hostility_level = {
						target = scope:recipient.faith
						value >= religious_cb_enabled_hostility_level
					}
				}
			}
		}
		scope:recipient = {
			is_alive = yes
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= pam_ecclesiastic_incite_holy_war_cost_value
			}
		}
	}

	has_valid_target_showing_failures_only = {
		exists = scope:target
		exists = scope:secondary_recipient
		scope:target = {
			tier <= tier_kingdom
			tier >= tier_county
			is_landless_type_title = no
			custom_tooltip = {
				text = sponsored_holy_war_target_must_be_held_by_recipient_tt
				any_in_de_jure_hierarchy = {
					tier = tier_county
					holder ?= {
						target_is_same_character_or_above = scope:recipient
					}
				}
			}
			custom_tooltip = {
				text = sponsored_holy_war_target_must_border_attacker_tt
				any_in_de_jure_hierarchy = {
					tier = tier_county
					holder ?= {
						target_is_same_character_or_above = scope:recipient
					}
					OR = {
						holder.top_liege = scope:secondary_recipient.top_liege
						any_title_to_title_neighboring_and_across_water_county = {
							holder.top_liege = scope:secondary_recipient.top_liege
						}
					}
				}
			}
		}
	}
	
	cost = {
		piety = {
			value = pam_ecclesiastic_incite_holy_war_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
			if = {
				limit = {
					scope:inspire_realm ?= yes
				}
				add = pam_ecclesiastic_incite_holy_war_inspire_realm_value
			}
			if = {
				limit = {
					scope:puppet_or_actor ?= {
						domicile ?= { has_domicile_parameter = estate_cheaper_incite_war_1 }
					}
				}
				multiply = ecclesiastical_domicile_cheaper_incite_war_mult_1
			}
			if = {
				limit = {
					scope:puppet_or_actor ?= {
						domicile ?= { has_domicile_parameter = estate_cheaper_incite_war_2 }
					}
				}
				multiply = ecclesiastical_domicile_cheaper_incite_war_mult_2
			}
			if = {
				limit = {
					scope:puppet_or_actor ?= {
						domicile ?= { has_domicile_parameter = estate_cheaper_incite_war_3 }
					}
				}
				multiply = ecclesiastical_domicile_cheaper_incite_war_mult_3
			}
			if = {
				limit = {
					scope:puppet_or_actor ?= { has_perk = chivalric_dominance_perk }
				}
				multiply = 0.75
			}
		}
	}

	send_option = {
		is_shown = {
			trigger_if = {
				limit = {
					exists = scope:secondary_recipient
				}
				scope:secondary_recipient = {
					is_ai = yes
				}
			}
		}
		is_valid = {
			trigger_if = {
				limit = {
					exists = scope:secondary_recipient
				}
				scope:actor = {
					has_usable_hook = scope:secondary_recipient
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = no_attacker_picked_tt
					always = no
				}
			}
		}
		flag = use_hook
		localization = EDUCATION_HOOK
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor ?= {
				trigger_if = {
					limit = {
						scope:actor = {
							is_ai = yes
						}
					}
					prestige_level >= 3
					ai_boldness > low_positive_ai_value
					ai_energy > low_positive_ai_value
					NOT = {
						religious_head_or_challenger ?= this
					}
				}
				NOR = {
					is_at_war_with = scope:recipient
					has_truce = scope:recipient
					is_vassal_or_below_of = scope:recipient
					is_tributary_of = scope:recipient
				}
				prestige_level >= 1
			}
		}
		flag = join_war
		localization = JOIN_WAR_INTERACTION_OPTION
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor ?= {
				trigger_if = {
					limit = {
						scope:actor = {
							is_ai = yes
						}
					}
					short_term_gold >= monumental_gold_value
				}
				trigger_else = {
					gold >= major_gold_value
				}
			}
		}
		flag = fund_war
		localization = FUND_WAR_INTERACTION_OPTION
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor ?= {
				custom_tooltip = {
					text = rally_crusaders_req_tt
					OR = {
						stewardship >= very_high_skill_rating
						martial >= very_high_skill_rating
						diplomacy >= very_high_skill_rating
					}
				}
				trigger_if = {
					limit = {
						scope:actor = { is_ai = yes }
					}
					prestige >= major_prestige_value
				}
			}
		}
		flag = rally_crusaders
		localization = RALLY_CRUSADERS_INTERACTION_OPTION
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor ?= {
				piety_level >= 3
				piety >= pam_ecclesiastic_incite_holy_war_inspire_realm_value
			}
		}
		flag = inspire_realm
		localization = INSPIRE_REALM_INTERACTION_OPTION
	}

	send_options_exclusive = no

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				if = {
					limit = { pam_ecclesiastic_incite_holy_war_cost_value > 0 }
					add_piety = {
						value = {
							add = pam_ecclesiastic_incite_holy_war_cost_value
							max = piety
							multiply = -1
						}
					}
				}
			}
		}
		if = {
			limit = {
				scope:puppet_or_actor ?= { has_perk = chivalric_dominance_perk }
			}
			scope:puppet_or_actor = {
				add_prestige = medium_prestige_value
			}
		}
		ecclesiastic_incite_holy_war_interaction_effect = yes
	}

	auto_accept = {
		OR = {
			#Player recipients auto-accept so they get no say in being attacked
			#Auto-accept skips ai_accept, so ai_will_do is stricter than usual
			scope:recipient = {
				is_ai = no
			}
			AND = {
				exists = scope:secondary_recipient
				custom_description = {
					text = "spending_hook"
					subject = scope:actor
					object = scope:secondary_recipient
					scope:use_hook = yes
					scope:actor = { has_strong_hook = scope:secondary_recipient }
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = rulers_in_clerical_region
	}
	ai_targets = {
		ai_recipients = neighboring_rulers
	}
	ai_targets = {
		ai_recipients = vassals
	}
	
	ai_accept = {
		base = -25

		modifier = {
			scope:inspire_realm = yes
			add = 50
			desc = INSPIRE_REALM_INTERACTION_OPTION_REASON
		}

		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_1
			desc = ESTATE_WARRIORS_VESTRY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_incite_war_vestry_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_2
			desc = ESTATE_WARRIORS_VESTRY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_incite_war_vestry_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_3
			desc = ESTATE_WARRIORS_VESTRY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_incite_war_vestry_3
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_1
			desc = ESTATE_RELIQUARY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_incite_war_reliquary_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_2
			desc = ESTATE_RELIQUARY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_incite_war_reliquary_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_3
			desc = ESTATE_RELIQUARY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_incite_war_reliquary_3
				}
			}
		}
		modifier = {
			add = 15
			desc = CHIVALRIC_DOMINANCE_REASON
			scope:puppet_or_actor ?= { has_perk = chivalric_dominance_perk }
		}

		modifier = {
			scope:rally_crusaders = yes
			add = {
				value = 25
				if = {
					limit = {
						scope:secondary_recipient ?= {
							highest_held_title_tier < scope:puppet_or_actor.highest_held_title_tier
							current_military_strength < scope:puppet_or_actor.current_military_strength
						}
					}
					add = 25
				}
			}
			desc = RALLY_CRUSADERS_INTERACTION_OPTION_REASON
		}

		# Weak hook: extra points
		modifier = {
			scope:use_hook = yes
			add = 100
			exists = scope:secondary_recipient
			scope:actor = { NOT = { has_strong_hook = scope:secondary_recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}

		modifier = {
			add = {
				value = 25
			}
			exists = scope:secondary_recipient
			scope:fund_war = yes
			scope:puppet_or_actor.major_gold_value < scope:secondary_recipient.minor_gold_value
			desc = FUND_HOLY_WAR_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 50
			}
			exists = scope:secondary_recipient
			scope:fund_war = yes
			scope:puppet_or_actor.major_gold_value < scope:secondary_recipient.major_gold_value
			scope:puppet_or_actor.major_gold_value >= scope:secondary_recipient.minor_gold_value
			desc = FUND_HOLY_WAR_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 75
			}
			exists = scope:secondary_recipient
			scope:fund_war = yes
			scope:puppet_or_actor.major_gold_value >= scope:secondary_recipient.major_gold_value
			scope:puppet_or_actor.major_gold_value < scope:secondary_recipient.monumental_gold_value
			desc = FUND_HOLY_WAR_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 100
			}
			exists = scope:secondary_recipient
			scope:fund_war = yes
			scope:puppet_or_actor.major_gold_value >= scope:secondary_recipient.monumental_gold_value
			desc = FUND_HOLY_WAR_INTERACTION_OPTION_REASON
		}

		#Title tier interest
		modifier = {
			exists = scope:secondary_recipient
			scope:target ?= {
				tier >= tier_kingdom
				any_de_jure_county = {
					count >= 5
					holder = {
						target_is_same_character_or_above = scope:recipient
					}
				}
			}
			scope:secondary_recipient.highest_held_title_tier >= tier_duchy
			add = 25
			desc = KINGDOM_TIER_REASON
		}
		modifier = {
			exists = scope:secondary_recipient
			scope:target ?= {
				tier = tier_duchy
				any_de_jure_county = {
					count >= 2
					holder = {
						target_is_same_character_or_above = scope:recipient
					}
				}
			}
			scope:secondary_recipient.highest_held_title_tier = tier_county
			add = 25
			desc = TARGET_TIER_REASON
		}
		modifier = {
			exists = scope:secondary_recipient
			scope:target ?= {
				tier = tier_county
			}
			scope:secondary_recipient.highest_held_title_tier >= tier_duchy
			add = {
				value = -25
				multiply = {
					value = scope:secondary_recipient.highest_held_title_tier
					subtract = 2
				}
			}
			desc = TARGET_TIER_REASON
		}
		modifier = {
			add = 25
			scope:secondary_recipient ?= {
				has_trait = holy_warrior
			}
			desc = ai_acceptance_trait_holy_warrior
		}
		#Join war option
		modifier = {
			exists = scope:secondary_recipient
			scope:join_war ?= yes
			add = {
				value = scope:actor.current_military_strength
				divide = { value = scope:secondary_recipient.current_military_strength min = 1 }
				multiply = 100
				round = yes
				max = 250
			}
			desc = CLERIC_JOIN_HOLY_WAR_REASON
		}

		modifier = {
			exists = scope:secondary_recipient
			scope:secondary_recipient.current_military_strength >= scope:recipient.fifty_percent_more_of_current_military_strength
			add = {
				value = scope:secondary_recipient.current_military_strength
				divide = { 
					value = scope:recipient.current_military_strength
					min = 1
				}
				multiply = 15
				round = yes
				max = 75
			}
			desc = SPONSORED_HOLY_WAR_RELATIVE_STRENGTH_REASON
		}
		modifier = {
			exists = scope:secondary_recipient
			scope:recipient.current_military_strength > scope:secondary_recipient.current_military_strength
			add = {
				value = scope:recipient.current_military_strength
				divide = { value = scope:secondary_recipient.current_military_strength min = 1 }
				multiply = -50
				round = yes
			}
			desc = SPONSORED_HOLY_WAR_RELATIVE_STRENGTH_REASON
		}
		modifier = {
			add = {
				value = scope:actor.piety_level
				multiply = 10
			}
			scope:actor.piety_level > 0
			desc = I_AM_PIOUS
		}
		modifier = {
			add = -200
			scope:secondary_recipient.rite ?= {
				rite_has_parameter = holy_wars_forbidden
			}
			desc = RITE_IS_PACIFIST
		}
		modifier = {
			add = -100
			scope:secondary_recipient.rite ?= {
				has_tenet_status = {
					tenet = tenet_peace_of_god
					status = core
				}
			}
			desc = pam_peace_of_god_incite_holy_war_reason
		}
		modifier = {
			add = -100
			scope:secondary_recipient ?= {
				any_personal_tenet = {
					OR = {
						this = tenet:tenet_pacifism
						this = tenet:tenet_dharmic_pacifism
					}
				}
			}
			desc = PERSONAL_TENET_PACIFISM
		}
		modifier = {
			add = -50
			exists = scope:secondary_recipient
			"scope:secondary_recipient.capital_province.squared_distance(scope:recipient.capital_province)" >= squared_distance_huge
			desc = PT_AI_IS_FAR_AWAY
		}
		opinion_modifier = {
			trigger = { exists = scope:secondary_recipient }
			who = scope:secondary_recipient
			opinion_target = scope:puppet_or_actor
			multiplier = 0.5
		}
		modifier = {
			add = -50
			scope:secondary_recipient ?= {
				opinion = {
					target = scope:recipient
					value >= 25
				}
			}
			desc = SECONDARY_RECIPIENT_LIKES_RECIPIENT_REASON
		}
		modifier = {
			add = -100
			scope:secondary_recipient ?= {
				has_any_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
			}
			desc = SECONDARY_RECIPIENT_GOOD_RELATION_WITH_RECIPIENT_REASON
		}
		modifier = {
			add = 30
			scope:secondary_recipient ?= {
				OR = {
					has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
					opinion = {
						target = scope:recipient
						value <= -95
					}
				}
			}
			desc = SECONDARY_RECIPIENT_LOATHES_RECIPIENT_REASON
		}
		modifier = {
			exists = scope:secondary_recipient
			scope:actor = {
				NOT = { rite = scope:secondary_recipient.rite }
			}
			add = -25
			desc = DIFFERENT_RITE_REASON
		}
		modifier = {
			exists = scope:secondary_recipient
			scope:actor = {
				NOT = { rite = scope:secondary_recipient.rite }
			}
			scope:secondary_recipient ?= {
				rite_fulfillment_score = {
					target = scope:actor.rite
					value >= 75
				}
			}
			add = 25
			desc = PERSONAL_APPROVAL_OF_RITE_REASON
		}
		modifier = {
			exists = scope:secondary_recipient
			scope:actor = {
				NOT = { rite = scope:secondary_recipient.rite }
			}
			scope:secondary_recipient ?= {
				rite_fulfillment_score = {
					target = scope:actor.rite
					value < 25
				}
			}
			add = -25
			desc = PERSONAL_DISAPPROVAL_OF_RITE_REASON_SECONDARY
		}
		#Your rite is heretical
		modifier = {
			exists = scope:secondary_recipient
			exists = scope:puppet_or_actor
			scope:puppet_or_actor = {
				NOT = { rite = scope:secondary_recipient.rite }
			}
			any_tenet = {
				scope:puppet_or_actor.rite = {
					has_tenet_status = {
						tenet = prev
						status = core
					}
				}
				scope:secondary_recipient.rite = {
					has_tenet_status = {
						tenet = prev
						status = prohibited
					}
				}
			}
			add = -100
			desc = RITE_CORE_TENET_PROHIBITED_SECONDARY
		}
		modifier = {
			exists = scope:secondary_recipient
			scope:actor = {
				NOT = { rite = scope:secondary_recipient.rite }
			}
			any_tenet = {
				scope:actor.rite = {
					has_tenet_status = {
						tenet = prev
						status = permitted
					}
				}
				scope:secondary_recipient.rite = {
					has_tenet_status = {
						tenet = prev
						status = prohibited
					}
				}
			}
			add = -40
			desc = RITE_TENET_PROHIBITED_SECONDARY
		}
		modifier = {
			scope:secondary_recipient ?= {
				OR = {
					ai_boldness > 0
					ai_boldness < 0
				}
			}
			add = {
				value = scope:secondary_recipient.ai_boldness
				multiply = 0.5
			} 
			desc = SECONDARY_RECIPIENT_BOLDNESS_REASON
		}
		modifier = {
			scope:secondary_recipient ?= {
				ai_compassion != 0
			}
			add = {
				value = scope:secondary_recipient.ai_compassion
				multiply = -0.25
			} 
			desc = SECONDARY_RECIPIENT_COMPASSION_REASON
		}
		modifier = {
			scope:secondary_recipient ?= {
				ai_zeal != 0
			}
			add = scope:secondary_recipient.ai_zeal
			desc = SECONDARY_RECIPIENT_ZEALOUSNESS_REASON
		}
		#No land border
		modifier = {
			exists = scope:target
			scope:secondary_recipient ?= {
				NOT = {
					any_sub_realm_county = {
						any_neighboring_county = {
							any_this_title_or_de_jure_above = {
								this = scope:target
							}
							holder ?= {
								OR = {
									target_is_same_character_or_above = scope:recipient
									target_is_same_character_or_above = scope:secondary_recipient
								}
							}
						}
					}
				}
			}
			add = {
				value = -50
			}
			desc = NOT_BORDERING_BY_LAND_REASON
		}
		#Recipient is already at war
		modifier = {
			scope:recipient = {
				is_at_war = yes
			}
			add = 40
			desc = RECIPIENT_AT_WAR_REASON
		}
		#Nomadic lands... therefore pretty worthless
		modifier = {
			exists = scope:target
			scope:secondary_recipient ?= {
				NOR = {
					government_has_flag = government_is_nomadic
					government_has_flag = government_is_steppe_admin
				}
			}
			scope:target.tier > tier_county
			scope:target = {
				any_de_jure_county = {
					holder = {
						target_is_same_character_or_above = scope:recipient
					}
					any_county_province = {
						is_county_capital = yes
						OR = {
							has_holding_type = nomad_holding
							has_holding_type = herder_holding
						}
					}
				}
			}
			add = {
				value = -30
				scope:target = {
					every_de_jure_county = {
						limit = {
							holder = {
								target_is_same_character_or_above = scope:recipient
							}
							any_county_province = {
								is_county_capital = yes
								OR = {
									has_holding_type = nomad_holding
									has_holding_type = herder_holding
								}
							}
						}
						add = -30
					}
				}
			}
			desc = NOMAD_LANDS_REASON
		}
		modifier = {
			exists = scope:target
			scope:secondary_recipient ?= {
				NOR = {
					government_has_flag = government_is_nomadic
					government_has_flag = government_is_steppe_admin
				}
			}
			scope:target.tier = tier_county
			scope:target = {
				any_county_province = {
					is_county_capital = yes
					OR = {
						has_holding_type = nomad_holding
						has_holding_type = herder_holding
					}
				}
			}
			add = -75
			desc = NOMAD_LANDS_REASON
		}
		modifier = {
			scope:recipient = {
				government_has_flag = government_is_nomadic
			}
			add = -25
			desc = NOMADIC_TARGET_REASON
		}
		modifier = {
			scope:recipient = {
				has_trait = conqueror
			}
			add = -50
			desc = RECIPIENT_CONQUEROR_REASON
		}
		modifier = {
			scope:recipient = {
				has_trait = greatest_of_khans
			}
			add = -100
			desc = RECIPIENT_GOK_REASON
		}
		# More likely to accept if you have an alliance
		modifier = {
			add = 50
			exists = scope:secondary_recipient
			scope:puppet_or_actor = { is_allied_to = scope:secondary_recipient }
			desc = AI_HAS_ALLIANCE
		}
		# Respect the liege
		modifier = {
			add = 25
			scope:secondary_recipient ?= { target_is_liege_or_above = scope:puppet_or_actor }
			desc = LIEGE_REASON_SECONDARY
		}
		# Actor is from the secondary_recipient's house
		modifier = { 
			add = 15
			exists = scope:puppet_or_actor.house
			scope:secondary_recipient ?= {
				is_close_or_extended_family_of = scope:puppet_or_actor
			}
			desc = YOU_ARE_MY_HOUSE_MEMBER_SECONDARY
		}
		#Close family member
		modifier = {
			scope:secondary_recipient ?= { is_close_family_of = scope:puppet_or_actor }
			add = 20
			desc = is_close_family_reason_SECONDARY
		}
		modifier = {
			exists = scope:puppet_or_actor.house
			NOT = { house ?= scope:puppet_or_actor.house }
			scope:secondary_recipient.dynasty ?= scope:puppet_or_actor.dynasty
			add = 10
			desc = AI_SAME_DYNASTY_REASON_SECONDARY
		}
		#You are house head
		modifier = {
			exists = scope:puppet_or_actor.house
			house.house_head ?= scope:puppet_or_actor
			add = 30
			desc = AI_YOU_ARE_THE_HOUSE_HEAD_SECONDARY
		}
		modifier = {
			exists = scope:puppet_or_actor.house
			NOT = { house.house_head ?= scope:puppet_or_actor }
			scope:secondary_recipient.dynasty.dynast ?= scope:puppet_or_actor
			add = 15
			desc = AI_YOU_ARE_THE_DYNAST_SECONDARY
		}
		#Very pious traits
		modifier = {
			scope:puppet_or_actor = {
				OR = {
					has_trait = saint
					has_trait = herald
					has_trait = saoshyant_descendant
					has_trait = saoshyant
					has_trait = paragon
					has_trait = savior
					has_trait = crusader_king
				}
			}
			add = 30
			desc = VERY_PIOUS_TRAITS_REASON
		}
		#Pious traits
		modifier = {
			scope:puppet_or_actor = {
				OR = {
					has_trait = zealous
					has_trait = theologian
					has_trait = divine_blood
					has_trait = consecrated_blood
					has_trait = sayyid
					has_trait = order_member
					has_trait = faith_warrior
				}
			}
			add = 10
			desc = PIOUS_TRAITS_REASON
		}
		# Fs
		modifier = { 
			add = 25
			scope:secondary_recipient ?= {
				has_relation_friend = scope:puppet_or_actor
			}
			desc = WE_ARE_FRIENDS
		}
		# BFFs
		modifier = { 
			add = 50
			scope:secondary_recipient ?= {
				has_relation_best_friend = scope:puppet_or_actor
			}
			desc = WE_ARE_BEST_FRIENDS
		}
		# Take dread into account
		modifier = {
			add = {
				value = 15
				if = {
					limit = {
						scope:secondary_recipient ?= {
							target_is_liege_or_above = scope:puppet_or_actor
						}
					}
					multiply = 2
				}
			}
			scope:secondary_recipient ?= {
				has_dread_level_towards = {
					target = scope:puppet_or_actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = {
				value = 30
				if = {
					limit = {
						scope:secondary_recipient ?= {
							target_is_liege_or_above = scope:puppet_or_actor
						}
					}
					multiply = 2
				}
			}
			scope:secondary_recipient ?= {
				has_dread_level_towards = {
					target = scope:puppet_or_actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		# Take dread into account
		modifier = {
			add = -50
			scope:secondary_recipient ?= {
				has_dread_level_towards = {
					target = scope:recipient
					level = 1
				}
			}
			desc = SECONDARY_INTIMIDATED_BY_RECIPIENT_REASON
		}
		modifier = {
			add = -150
			scope:secondary_recipient ?= {
				has_dread_level_towards = {
					target = scope:recipient
					level >= 2
				}
			}
			desc = SECONDARY_COWED_BY_RECIPIENT_REASON
		}
	}

	can_send_despite_rejection = no

	ai_targets = {
		ai_recipients = neighboring_rulers_including_tributary_borders
		ai_recipients = war_enemies
		ai_recipients = rulers_in_clerical_region
		max = 10
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 60
		kingdom = 24
		empire = 24
		hegemony = 24
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = 25
			scope:recipient.rite = {
				"divergence(faith.main_rite)" >= minor_rite_divergence_value
			}
			desc = grant_pope_blessing_high_divergence_reason
		}

		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
		}
		
		modifier = {
			scope:puppet_or_actor = {
				top_participant_group:the_christian_church ?= {
					has_participant_group_parameter = the_christian_church_incite_holy_war_interaction
				}
			}
			add = 50
		}

		modifier = {
			add = 25
			scope:recipient = {
				is_at_war = yes
			}
		}
		modifier = {
			add = 25
			exists = scope:secondary_recipient
			scope:secondary_recipient.current_military_strength > scope:recipient.twice_current_military_strength
		}
		modifier = {
			add = {
				value = scope:actor.ai_zeal
				multiply = 1
			}
		}
		modifier = {
			add = {
				value = scope:actor.ai_compassion
				multiply = -0.5
			}
		}
		modifier = {
			add = {
				value = scope:actor.ai_boldness
				multiply = 0.5
			}
		}
		modifier = {
			factor = 2
			scope:puppet_or_actor.rite = {
				rite_hostility_level = {
					target = scope:recipient.rite
					value >= faith_evil_level
				}
			}
		}
		modifier = {
			factor = 0.5
			scope:puppet_or_actor = {
				piety < monumental_piety_value
			}
		}
		modifier = {
			factor = 0
			OR = { 
				AND = {
					exists = scope:secondary_recipient
					scope:secondary_recipient.current_military_strength < scope:recipient.current_military_strength
				}
				#AI will auto-accept when targeting players, so detailed factors needed here
				AND = {
					exists = scope:secondary_recipient
					scope:recipient = { is_ai = no }
					incite_holy_war_ai_invalidation_trigger = { RECIPIENT = scope:recipient SECONDARY = scope:secondary_recipient }
				}
			}
		}
	}
}

#Sponsor a same-faith secular ruler's claim war against another secular ruler
ecclesiastic_incite_claim_war_interaction = {
	category = interaction_category_diplomacy
	icon = ecclesiastic_incite_claim_war_interaction
	interface_priority = 74
	common_interaction = yes
	target_type = title
	target_filter = realm_titles
	target_source = recipient
	notification_text = ecclesiastic_incite_claim_war_interaction_notification
	greeting = negative
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = no
	cooldown_against_recipient = { years = 5 }
	use_diplomatic_range = no

	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			piety >= 750
			piety_level >= 2
			government_has_flag = government_is_theocracy
			OR = {
				rite.head_of_rite ?= this
				faith.religious_head ?= this
			}
			is_at_war = no
		}
	}

	is_shown = {
		has_pam_dlc_trigger = yes
		scope:puppet_or_actor ?= {
			government_has_flag = government_is_theocracy
		}
		scope:recipient = {
			is_landed = yes
			NOT = { government_has_flag = government_is_theocracy }
			this != scope:puppet_or_actor
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				is_independent_ruler = yes
			}
		}
	}

	populate_recipient_list = {
		if = {
			limit = { scope:actor = { is_ai = yes } }
			scope:puppet_or_actor = {
				faith = {
					every_faith_ruler = {
						limit = {
							valid_claim_war_incited_attacker_trigger = { RECIPIENT = scope:recipient }
						}
						add_to_list = characters
					}
				}
			}
		}
		else = {
			if = {
				limit = { exists = scope:target }
				scope:target = {
					every_claimant = {
						limit = {
							is_alive = yes
							this != scope:recipient
							this != scope:actor
							this != scope:puppet_or_actor
						}
						add_to_list = characters
					}
				}
			}
			else = {
				scope:recipient = {
					every_held_title = {
						limit = {
							tier >= tier_county
							tier <= tier_kingdom
							is_landless_type_title = no
						}
						every_claimant = {
							limit = {
								is_alive = yes
								this != scope:recipient
								this != scope:actor
								this != scope:puppet_or_actor
							}
							add_to_list = characters
						}
					}
					every_vassal_or_below = {
						limit = { is_landed = yes }
						every_held_title = {
							limit = {
								tier >= tier_county
								tier <= tier_kingdom
								is_landless_type_title = no
							}
							every_claimant = {
								limit = {
									is_alive = yes
									this != scope:recipient
									this != scope:actor
									this != scope:puppet_or_actor
								}
								add_to_list = characters
							}
						}
					}
				}
			}
		}
	}

	can_be_picked_title = {
		scope:target = {
			incite_claim_war_title_can_be_picked_trigger = { RECIPIENT = scope:recipient SECONDARY = scope:secondary_recipient }
		}
	}

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			is_available_quick = {
				adult = yes
				alive = yes
				imprisoned = no
				incapable = no
			}

			trigger_if = {
				limit = {
					scope:target ?= {
						tier >= tier_kingdom
					}
				}
				custom_tooltip = {
					text = piety_too_low_target_kingdom_tt
					piety_level >= 4
				}
			}
			trigger_else_if = {
				limit = {
					scope:target ?= {
						tier >= tier_duchy
					}
				}
				custom_tooltip = {
					text = piety_too_low_target_duchy_tt
					piety_level >= 3
				}
			}
			trigger_else = {
				piety_level >= 2
			}
			trigger_if = {
				limit = {
					scope:recipient = { is_independent_ruler = yes }
				}
				custom_tooltip = {
					text = no_valid_sponsored_claim_war_attacker_tt
					faith = {
						any_faith_ruler = {
							valid_claim_war_incited_attacker_trigger = { RECIPIENT = scope:recipient }
						}
					}
				}
			}
		}
		scope:recipient = {
			is_alive = yes
			custom_tooltip = {
				text = incite_claim_war_use_on_liege_tt
				is_independent_ruler = yes
			}
		}
		trigger_if = {
			limit = { scope:puppet_or_actor != scope:actor }
			scope:puppet_or_actor = {
				piety >= pam_ecclesiastic_incite_claim_war_cost_value
			}
		}
		trigger_if = {
			limit = { exists = scope:secondary_recipient }
			scope:secondary_recipient = {
				claim_war_incited_attacker_can_be_picked_trigger = { RECIPIENT = scope:recipient }
			}
		}
	}

	has_valid_target_showing_failures_only = {
		exists = scope:target
		exists = scope:secondary_recipient
		scope:target = {
			tier <= tier_kingdom
			tier >= tier_county
			is_landless_type_title = no
			custom_tooltip = {
				text = sponsored_claim_war_target_must_be_held_by_recipient_tt
				holder ?= {
					target_is_same_character_or_above = scope:recipient
				}
			}
			custom_tooltip = {
				text = sponsored_claim_war_attacker_must_have_claim_tt
				scope:secondary_recipient = { has_claim_on = scope:target }
			}
		}
	}

	cost = {
		piety = {
			value = pam_ecclesiastic_incite_claim_war_cost_value
			if = {
				limit = { scope:puppet_or_actor != scope:actor }
				multiply = 0
			}
			if = {
				limit = {
					scope:puppet_or_actor ?= {
						domicile ?= { has_domicile_parameter = estate_cheaper_incite_war_1 }
					}
				}
				multiply = ecclesiastical_domicile_cheaper_incite_war_mult_1
			}
			if = {
				limit = {
					scope:puppet_or_actor ?= {
						domicile ?= { has_domicile_parameter = estate_cheaper_incite_war_2 }
					}
				}
				multiply = ecclesiastical_domicile_cheaper_incite_war_mult_2
			}
			if = {
				limit = {
					scope:puppet_or_actor ?= {
						domicile ?= { has_domicile_parameter = estate_cheaper_incite_war_3 }
					}
				}
				multiply = ecclesiastical_domicile_cheaper_incite_war_mult_3
			}
			if = {
				limit = {
					scope:puppet_or_actor ?= { has_perk = chivalric_dominance_perk }
				}
				multiply = 0.75
			}
			if = {
				limit = { scope:appeal_to_gods_will ?= yes }
				add = major_piety_value
			}
		}
	}

	send_option = {
		is_shown = {
			trigger_if = {
				limit = {
					exists = scope:secondary_recipient
				}
				scope:secondary_recipient = {
					is_ai = yes
				}
			}
		}
		is_valid = {
			trigger_if = {
				limit = {
					exists = scope:secondary_recipient
				}
				scope:actor = {
					has_usable_hook = scope:secondary_recipient
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = no_attacker_picked_tt
					always = no
				}
			}
		}
		flag = use_hook
		localization = EDUCATION_HOOK
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor ?= {
				trigger_if = {
					limit = {
						scope:actor = {
							is_ai = yes
						}
					}
					prestige_level >= 3
					ai_boldness > low_positive_ai_value
					ai_energy > low_positive_ai_value
					NOT = {
						religious_head_or_challenger ?= this
					}
				}
				NOR = {
					is_at_war_with = scope:recipient
					has_truce = scope:recipient
					is_vassal_or_below_of = scope:recipient
					is_tributary_of = scope:recipient
				}
				prestige_level >= 1
			}
		}
		flag = join_war
		localization = JOIN_WAR_INTERACTION_OPTION
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor ?= {
				trigger_if = {
					limit = {
						scope:actor = {
							is_ai = yes
						}
					}
					short_term_gold >= monumental_gold_value
				}
				trigger_else = {
					gold >= major_gold_value
				}
			}
		}
		flag = fund_war
		localization = FUND_WAR_INTERACTION_OPTION
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor ?= {
				piety >= major_piety_value
			}
		}
		flag = appeal_to_gods_will
		localization = APPEAL_TO_GODS_WILL_INTERACTION_OPTION
	}

	send_options_exclusive = no

	on_accept = {
		if = {
			limit = { scope:puppet_or_actor != scope:actor }
			scope:puppet_or_actor = {
				if = {
					limit = { pam_ecclesiastic_incite_claim_war_cost_value > 0 }
					add_piety = {
						value = {
							add = pam_ecclesiastic_incite_claim_war_cost_value
							max = piety
							multiply = -1
						}
					}
				}
			}
		}
		if = {
			limit = {
				scope:puppet_or_actor ?= { has_perk = chivalric_dominance_perk }
			}
			scope:puppet_or_actor = {
				add_prestige = medium_prestige_value
			}
		}
		ecclesiastic_incite_claim_war_interaction_effect = yes
	}

	auto_accept = {
		OR = {
			scope:recipient = {
				is_ai = no
			}
			AND = {
				exists = scope:secondary_recipient
				custom_description = {
					text = "spending_hook"
					subject = scope:actor
					object = scope:secondary_recipient
					scope:use_hook = yes
					scope:actor = { has_strong_hook = scope:secondary_recipient }
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = rulers_in_clerical_region
	}
	ai_targets = {
		ai_recipients = neighboring_rulers
	}
	ai_targets = {
		ai_recipients = vassals
	}
	ai_targets = {
		ai_recipients = neighboring_rulers_including_tributary_borders
		ai_recipients = war_enemies
		ai_recipients = rulers_in_clerical_region
		max = 10
	}

	ai_accept = {
		base = -25

		modifier = {
			scope:appeal_to_gods_will = yes
			add = 50
			desc = APPEAL_TO_GODS_WILL_INTERACTION_OPTION_REASON
		}

		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_1
			desc = ESTATE_WARRIORS_VESTRY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_incite_war_vestry_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_2
			desc = ESTATE_WARRIORS_VESTRY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_incite_war_vestry_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_3
			desc = ESTATE_WARRIORS_VESTRY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_incite_war_vestry_3
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_1
			desc = ESTATE_RELIQUARY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_incite_war_reliquary_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_2
			desc = ESTATE_RELIQUARY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_incite_war_reliquary_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_3
			desc = ESTATE_RELIQUARY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_incite_war_reliquary_3
				}
			}
		}
		modifier = {
			add = 15
			desc = CHIVALRIC_DOMINANCE_REASON
			scope:puppet_or_actor ?= { has_perk = chivalric_dominance_perk }
		}

		modifier = {
			scope:use_hook = yes
			add = 100
			exists = scope:secondary_recipient
			scope:actor = { NOT = { has_strong_hook = scope:secondary_recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}

		modifier = {
			add = {
				value = 25
			}
			exists = scope:secondary_recipient
			scope:fund_war = yes
			scope:puppet_or_actor.major_gold_value < scope:secondary_recipient.minor_gold_value
			desc = FUND_HOLY_WAR_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 50
			}
			exists = scope:secondary_recipient
			scope:fund_war = yes
			scope:puppet_or_actor.major_gold_value < scope:secondary_recipient.major_gold_value
			scope:puppet_or_actor.major_gold_value >= scope:secondary_recipient.minor_gold_value
			desc = FUND_HOLY_WAR_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 75
			}
			exists = scope:secondary_recipient
			scope:fund_war = yes
			scope:puppet_or_actor.major_gold_value >= scope:secondary_recipient.major_gold_value
			scope:puppet_or_actor.major_gold_value < scope:secondary_recipient.monumental_gold_value
			desc = FUND_HOLY_WAR_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 100
			}
			exists = scope:secondary_recipient
			scope:fund_war = yes
			scope:puppet_or_actor.major_gold_value >= scope:secondary_recipient.monumental_gold_value
			desc = FUND_HOLY_WAR_INTERACTION_OPTION_REASON
		}

		modifier = {
			exists = scope:secondary_recipient
			scope:secondary_recipient.highest_held_title_tier >= tier_duchy
			add = {
				value = scope:secondary_recipient.highest_held_title_tier
				subtract = 2
				multiply = -25
			}
			desc = INCITE_CLAIM_WAR_ATTACKER_TIER_REASON
		}
		modifier = {
			exists = scope:secondary_recipient
			scope:target ?= {
				tier >= tier_kingdom
			}
			scope:secondary_recipient.highest_held_title_tier >= tier_duchy
			add = 25
			desc = KINGDOM_TIER_REASON
		}
		modifier = {
			exists = scope:secondary_recipient
			scope:target ?= {
				tier = tier_duchy
			}
			scope:secondary_recipient.highest_held_title_tier = tier_county
			add = 25
			desc = TARGET_TIER_REASON
		}
		modifier = {
			exists = scope:secondary_recipient
			scope:target ?= {
				tier = tier_county
			}
			scope:secondary_recipient.highest_held_title_tier >= tier_duchy
			add = {
				value = -25
				multiply = {
					value = scope:secondary_recipient.highest_held_title_tier
					subtract = 2
				}
			}
			desc = TARGET_TIER_REASON
		}

		modifier = {
			exists = scope:secondary_recipient
			scope:join_war ?= yes
			add = {
				value = scope:actor.current_military_strength
				divide = { value = scope:secondary_recipient.current_military_strength min = 1 }
				multiply = 100
				round = yes
				max = 250
			}
			desc = CLERIC_JOIN_HOLY_WAR_REASON
		}

		modifier = {
			exists = scope:secondary_recipient
			scope:secondary_recipient.current_military_strength >= scope:recipient.fifty_percent_more_of_current_military_strength
			add = {
				value = scope:secondary_recipient.current_military_strength
				divide = {
					value = scope:recipient.current_military_strength
					min = 1
				}
				multiply = 15
				round = yes
				max = 75
			}
			desc = SPONSORED_HOLY_WAR_RELATIVE_STRENGTH_REASON
		}
		modifier = {
			exists = scope:secondary_recipient
			scope:recipient.current_military_strength > scope:secondary_recipient.current_military_strength
			add = {
				value = scope:recipient.current_military_strength
				divide = { value = scope:secondary_recipient.current_military_strength min = 1 }
				multiply = -50
				round = yes
			}
			desc = SPONSORED_HOLY_WAR_RELATIVE_STRENGTH_REASON
		}
		modifier = {
			add = {
				value = scope:actor.piety_level
				multiply = 10
			}
			scope:actor.piety_level > 0
			desc = I_AM_PIOUS
		}
		modifier = {
			add = -100
			scope:secondary_recipient ?= {
				any_personal_tenet = {
					OR = {
						this = tenet:tenet_pacifism
						this = tenet:tenet_dharmic_pacifism
					}
				}
			}
			desc = PERSONAL_TENET_PACIFISM
		}
		modifier = {
			add = -50
			exists = scope:secondary_recipient.capital_province
			exists = scope:recipient.capital_province
			"scope:secondary_recipient.capital_province.squared_distance(scope:recipient.capital_province)" >= squared_distance_huge
			desc = PT_AI_IS_FAR_AWAY
		}
		opinion_modifier = {
			trigger = { exists = scope:secondary_recipient }
			who = scope:secondary_recipient
			opinion_target = scope:puppet_or_actor
			multiplier = 0.5
		}
		modifier = {
			add = -50
			scope:secondary_recipient ?= {
				opinion = {
					target = scope:recipient
					value >= 25
				}
			}
			desc = SECONDARY_RECIPIENT_LIKES_RECIPIENT_REASON
		}
		modifier = {
			add = -100
			scope:secondary_recipient ?= {
				has_any_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
			}
			desc = SECONDARY_RECIPIENT_GOOD_RELATION_WITH_RECIPIENT_REASON
		}
		modifier = {
			add = 30
			scope:secondary_recipient ?= {
				OR = {
					has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
					opinion = {
						target = scope:recipient
						value <= -95
					}
				}
			}
			desc = SECONDARY_RECIPIENT_LOATHES_RECIPIENT_REASON
		}
		modifier = {
			scope:secondary_recipient ?= {
				OR = {
					ai_boldness > 0
					ai_boldness < 0
				}
			}
			add = {
				value = scope:secondary_recipient.ai_boldness
				multiply = 0.5
			}
			desc = SECONDARY_RECIPIENT_BOLDNESS_REASON
		}
		modifier = {
			scope:secondary_recipient ?= {
				ai_compassion != 0
			}
			add = {
				value = scope:secondary_recipient.ai_compassion
				multiply = -0.25
			}
			desc = SECONDARY_RECIPIENT_COMPASSION_REASON
		}
		modifier = {
			scope:recipient = {
				is_at_war = yes
			}
			add = 40
			desc = RECIPIENT_AT_WAR_REASON
		}
		modifier = {
			add = 50
			exists = scope:secondary_recipient
			scope:puppet_or_actor = { is_allied_to = scope:secondary_recipient }
			desc = AI_HAS_ALLIANCE
		}
		modifier = {
			add = 25
			scope:secondary_recipient ?= { target_is_liege_or_above = scope:puppet_or_actor }
			desc = LIEGE_REASON_SECONDARY
		}
		modifier = {
			add = -50
			scope:secondary_recipient ?= {
				has_dread_level_towards = {
					target = scope:recipient
					level = 1
				}
			}
			desc = SECONDARY_INTIMIDATED_BY_RECIPIENT_REASON
		}
		modifier = {
			add = -150
			scope:secondary_recipient ?= {
				has_dread_level_towards = {
					target = scope:recipient
					level >= 2
				}
			}
			desc = SECONDARY_COWED_BY_RECIPIENT_REASON
		}
	}

	can_send_despite_rejection = no

	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 60
		kingdom = 48
		empire = 24
		hegemony = 24
	}

	ai_will_do = {
		base = 0

		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
		}

		modifier = {
			add = 25
			scope:recipient = {
				is_at_war = yes
			}
		}
		modifier = {
			add = 25
			exists = scope:secondary_recipient
			scope:secondary_recipient.current_military_strength > scope:recipient.twice_current_military_strength
		}
		modifier = {
			add = {
				value = scope:actor.ai_zeal
				multiply = 0.5
			}
		}
		modifier = {
			add = {
				value = scope:actor.ai_compassion
				multiply = -0.5
			}
		}
		modifier = {
			add = {
				value = scope:actor.ai_boldness
				multiply = 0.5
			}
		}
		modifier = {
			factor = 0.5
			scope:puppet_or_actor = {
				piety < monumental_piety_value
			}
		}
		modifier = {
			factor = 0
			OR = {
				AND = {
					exists = scope:secondary_recipient
					scope:secondary_recipient.current_military_strength < scope:recipient.current_military_strength
				}
				AND = {
					exists = scope:secondary_recipient
					scope:recipient = { is_ai = no }
					incite_holy_war_ai_invalidation_trigger = { RECIPIENT = scope:recipient SECONDARY = scope:secondary_recipient }
				}
			}
		}
	}
}

# Reduces a rite's divergence score
grant_pope_blessing_interaction = {
	category = interaction_category_religion
	icon = religious

	use_diplomatic_range = no
	auto_accept = yes

	desc = grant_pope_blessing_interaction_desc

	is_available = {
		faith.religious_head ?= this
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:recipient = {
			rite.head_of_rite ?= this
			faith ?= scope:actor.faith
			this != scope:actor
			rite ?= {
				NOT = { rite_has_doctrine = special_doctrine_pope_blessing }
			}
			is_ai = yes
		}
	}
	
	cost = {
		piety = massive_piety_value
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			is_alive = yes
			custom_tooltip = {
				text = grant_pope_blessing_hor_tt
				rite.head_of_rite ?= this
			}
		}
	}

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				title = grant_pope_blessing_toast_title
				desc = grant_pope_blessing_toast_desc
				left_icon = scope:actor
				right_icon = scope:recipient
				faith = {
					change_fervor = {
						value = notable_fervor_loss
						desc = fervor_loss_grant_pope_blessing
					}
				}
				scope:recipient = {
					add_opinion = {
						target = scope:actor
						modifier = grateful_opinion
						opinion = 15
					}
					rite = { add_rite_doctrine = special_doctrine_pope_blessing }
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = rulers_in_clerical_region
		ai_recipients = neighboring_rulers
		ai_recipients = vassals
		ai_recipients = subordinates
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 144
		kingdom = 36
		empire = 36
		hegemony = 36
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = 50
			scope:recipient.rite = {
				"divergence(faith.main_rite)" >= minor_rite_divergence_value
			}
			desc = grant_pope_blessing_high_divergence_reason
		}

		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
		}
	}
}

# Make a cardinal vote for whoever you want
influence_papal_vote_interaction = {
	category = interaction_category_religion
	icon = influence_papal_vote_interaction
	common_interaction = no
	interface_priority = 74

	filter_tags = { papabile }

	use_diplomatic_range = yes
	ai_maybe = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes

	cooldown_against_recipient = { years = 10 }

	desc = influence_papal_vote_interaction_desc
	notification_text = influence_papal_vote_interaction_notification

	is_available = {
		faith = { has_doctrine_parameter = has_clerical_electors }
		pam_pope_is_head_of_faith_or_rite_trigger = yes
		is_adult = yes
		NOR = {
			government_has_flag = government_is_mercenary
			government_has_flag = government_is_herder
		}
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:recipient = {
			faith ?= scope:actor.faith
			exists = clerical_elector_title
			is_ruler = yes
			is_adult = yes
			this != scope:actor
		}
	}

	populate_recipient_list = {
		scope:actor.faith = {
			every_clerical_elector_title = {
				holder ?= {
					if = {
						limit = {
							this != scope:recipient
							NOT = { scope:actor.faith.religious_head ?= this }
							is_alive = yes
							is_papabile = yes
						}
						add_to_list = characters
					}
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_imprisoned = no
			is_at_war = no
			is_incapable = no
			piety_level >= high_piety_level
		}
		scope:recipient = {
			is_imprisoned = no
			is_at_war = no
			is_incapable = no
			NOT = { has_trait = excommunicated }
		}
	}

	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
			scope:recipient = {
				NOT = { is_imprisoned_by = scope:actor }
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_option = {
		flag = pam_papal_vote_bribe
		localization = influence_papal_vote_bribe_option_desc
		is_valid = {
			scope:actor = { gold >= major_gold_value }
		}
	}
	send_options_exclusive = no

	cost = {
		piety = {
			value = major_piety_value
			if = {
				limit = {
					scope:actor = {
						domicile ?= { has_domicile_parameter = estate_cheaper_papal_vote }
					}
				}
				multiply = ecclesiastical_domicile_cheaper_papal_vote_mult
			}
		}
	}

	auto_accept = {
		custom_tooltip = {
			text = influence_papal_vote_autoaccept_tt
			OR = {
				custom_description = {
					text = "spending_hook"
					subject = scope:actor
					object = scope:recipient
					scope:hook = yes
					scope:actor = { has_strong_hook = scope:recipient }
				}
				custom_description = {
					text = "influence_papal_vote_is_puppet_tt"
					scope:recipient.puppeteer ?= scope:actor
				}
			}
		}
	}

	on_accept = {
		scope:actor = {
			if = {
				limit = {
					scope:hook = yes
					has_usable_hook = scope:recipient
				}
				use_hook = scope:recipient
			}
			send_interface_toast = {
				type = event_toast_effect_good
				title = influence_papal_vote_interaction_toast
				left_icon = scope:actor
				right_icon = scope:recipient
				custom_tooltip = influence_papal_vote_interaction_tt
				scope:recipient = {
					set_variable = {
						name = pam_forced_papal_vote_target
						value = scope:secondary_recipient
						years = 20
					}
					# Rather than waiting for the next AI tick, force update views immediately
					hidden_effect = {
						recalculate_succession_election_vote = yes
					}
				}
				if = {
					limit = { scope:pam_papal_vote_bribe = yes }
					pay_short_term_gold = {
						target = scope:recipient
						gold = major_gold_value
					}
				}
			}
		}
		if = {
			limit = {
				exists = scope:actor.top_participant_group:the_christian_church
				scope:actor = {
					NOT = { government_has_flag = government_is_theocracy }
				}
				situation:the_christian_church ?= {
					situation_top_has_catalyst = catalyst_secular_interference_in_papal_election
				}
			}
			situation:the_christian_church = {
				trigger_situation_catalyst = catalyst_secular_interference_in_papal_election
			}
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = influence_papal_vote_interaction_decline_toast
				right_icon = scope:recipient
				scope:recipient = {
					add_opinion = {
						target = scope:actor
						modifier = annoyed_opinion
						opinion = -10
					}
				}
			}
		}
	}

	ai_accept = {
		base = -80

		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}

		modifier = { # Your Intrigue
			add = {
				value = scope:actor.intrigue
				multiply = 1.5
			}
			desc = INTERACTION_ACTOR_INTRIGUE
		}

		modifier = { # Court of Shadows
			add = 20
			scope:actor = { has_perk = court_of_shadows_perk }
			desc = COURT_OF_SHADOWS_PAPAL_VOTE_REASON
		}

		modifier = {
			add = ecclesiastical_domicile_acceptance_value_1
			desc = ESTATE_PAPAL_VOTE_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_easier_papal_vote_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_value_2
			desc = ESTATE_PAPAL_VOTE_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_easier_papal_vote_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_value_3
			desc = ESTATE_PAPAL_VOTE_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_easier_papal_vote_3
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_1
			desc = ESTATE_ELECTION_COFFERS_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_papal_vote_coffers_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_2
			desc = ESTATE_ELECTION_COFFERS_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_papal_vote_coffers_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_3
			desc = ESTATE_ELECTION_COFFERS_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_papal_vote_coffers_3
				}
			}
		}
		ecclesiastical_domicile_cathedral_awe_modifier = yes

		modifier = { # Used a hook
			scope:hook = yes
			add = 50
			scope:actor = { NOT = { has_strong_hook = scope:recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}

		modifier = { # Bribe + they're greedy
			add = 80
			scope:pam_papal_vote_bribe = yes
			scope:recipient = { ai_greed >= 20 }
			desc = AI_GREED_REASON
		}

		modifier = { # Bribe
			add = 40
			scope:pam_papal_vote_bribe = yes
			scope:recipient = {
				ai_greed < 20
			}
			desc = AI_BRIBE_REASON
		}

		modifier = { # Dread
			add = 50
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}

		modifier = { # Dread
			add = 25
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}

		modifier = { # Friends
			add = 80
			scope:recipient = {
				OR = {
					has_relation_friend = scope:actor
					has_relation_lover = scope:actor
				}
			}
			desc = WE_ARE_FRIENDS
		}

		modifier = { # BFFs
			add = 40
			scope:recipient = { has_relation_best_friend = scope:actor }
			desc = WE_ARE_BEST_FRIENDS
		}
		
		modifier = { # Dynasty
			add = 80
			scope:recipient.dynasty ?= scope:actor.dynasty
			desc = AI_SAME_DYNASTY_REASON
		}
		
		modifier = { # Close Family
			add = 100
			scope:recipient = {
				is_close_family_of = scope:actor
			}
			desc = AI_FAMILY_REASON
		}

		modifier = { # They like who you're asking them to vote for
			add = 25
			exists = scope:secondary_recipient
			scope:recipient = {
				opinion = {
					target = scope:secondary_recipient
					value >= 50
				}
			}
			desc = INFLUENCE_PAPAL_VOTE_LIKES_CANDIDATE_REASON
		}

		modifier = { # They're just
			add = -30
			scope:recipient = { has_trait = just }
			desc = INFLUENCE_PAPAL_VOTE_JUST_REASON
		}

		modifier = { # They're pious
			add = {
				value = scope:recipient.piety_level
				multiply = -15
			}
			scope:recipient.piety_level > 0
			desc = RECIPIENT_IS_PIOUS
		}

		modifier = { # They're rivals with the candidate
			add = -50
			exists = scope:secondary_recipient
			scope:recipient = { has_relation_rival = scope:secondary_recipient }
			desc = INFLUENCE_PAPAL_VOTE_RIVAL_CANDIDATE_REASON
		}

		modifier = { # You're sinful
			add = {
				value = scope:actor.num_sinful_traits
				multiply = -10
			}
			scope:actor.num_sinful_traits > 0
			desc = I_AM_SINFUL
		}
	}

	ai_targets = {
		ai_recipients = rulers_in_clerical_region
		max = 5
	}
	
	ai_targets = {
		ai_recipients = clerical_region_rulers_in_realm
		ai_recipients = puppets
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 72
		kingdom = 48
		empire = 36
		hegemony = 36
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = 20
			OR = {
				has_usable_hook = scope:recipient
				scope:recipient.puppeteer ?= this
			}
			OR = {
				has_trait = ambitious
				has_trait = deceitful
				has_trait = cynical
			}
		}

		modifier = {
			factor = 0
			piety_level < high_piety_level
		}

		modifier = {
			factor = 0
			exists = clerical_elector_title
		}

		modifier = {
			factor = 0
			piety < major_piety_value
		}
	}
}

increase_papabile_score_interaction = {
	category = interaction_category_religion
	icon = icon_increase_theocratic_heir_candidacy
	common_interaction = yes
	interface_priority = 75
	
	cooldown_against_recipient = { years = 3 }
	
	filter_tags = { papabile }

	desc = increase_papabile_score_interaction_desc
	filter_tags = { papabile }

	is_available = {
		faith ?= { has_doctrine_parameter = has_clerical_electors }
		pam_pope_is_head_of_faith_or_rite_trigger = yes
		title:k_papal_state ?= {
			any_elector = {}
			is_title_created = yes
		}
		is_adult = yes
		NOR = {
			government_has_flag = government_is_mercenary
			government_has_flag = government_is_herder
			government_has_flag = government_is_military_holy_order
		}
		has_pam_dlc_trigger = yes
		trigger_if = {
			# The incumbent stands in no conclave, so the AI Head of Faith has no candidacy worth buying
			limit = { is_ai = yes }
			NOT = { faith.religious_head ?= this }
		}
	}

	is_shown = {
		scope:recipient = {
			faith ?= scope:actor.faith
			is_adult = yes
			exists = clerical_elector_title
			NOT = { faith.religious_head ?= this }
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_imprisoned = no
			is_at_war = no
			is_incapable = no
			trigger_if = {
				limit = {
					is_ai = yes
				}
				scope:recipient = {
					OR = {
						is_papabile = yes
						is_close_or_extended_family_of = scope:actor
						custom_tooltip = {
							text = increase_papabile_score_interaction_puppet_tt
							OR = {
								scope:actor.puppet:theological_agent_puppet ?= scope:recipient
								scope:actor.puppet:external_theological_agent_puppet ?= scope:recipient
							}
						}
					}
				}
			}
		}
		scope:recipient = {
			is_imprisoned = no
			is_at_war = no
			is_incapable = no
			NOT = { has_trait = excommunicated }
		}
	}

	send_option = {
		flag = pam_papabile_place_first_option
		localization = increase_papabile_score_place_first_option_desc
		is_valid = {
			scope:actor = { is_ai = no }
			custom_tooltip = {
				text = increase_papabile_score_already_powerful_tt
				scope:recipient = {
					pam_papabile_slot_open_to_trigger = { SLOT = theocratic_elective_powerful }
				}
			}
		}
	}

	send_option = {
		flag = pam_papabile_gold_option
		localization = increase_papabile_score_gold_option_desc
		is_valid = {
			scope:actor = { gold >= major_gold_value }
			custom_tooltip = {
				text = increase_papabile_score_gold_option_place_first_tt
				NOT = { scope:pam_papabile_place_first_option = yes }
			}
		}
	}
	send_options_exclusive = no

	localization_values = {
		PAM_PAPABILE_PLACE_FIRST = scope:recipient.pam_papabile_place_first_powerful_value
	}

	cost = {
		piety = {
			value = major_piety_value
			if = {
				limit = { scope:pam_papabile_place_first_option = yes }
				add = {
					value = scope:recipient.pam_papabile_place_first_powerful_value
					multiply = pam_papabile_place_first_piety_per_point_value
				}
			}
			if = {
				limit = { scope:actor = { has_perk = court_of_shadows_perk } }
				multiply = 0.75
			}
		}
		gold = {
			value = 0
			if = {
				limit = {
					scope:pam_papabile_gold_option = yes
					NOT = { scope:pam_papabile_place_first_option = yes }
				}
				add = scope:actor.major_gold_value
			}
		}
	}

	auto_accept = yes

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = increase_papabile_score_interaction_toast
				left_icon = scope:actor
				right_icon = scope:recipient
				scope:recipient = {
					if = {
						limit = { scope:pam_papabile_place_first_option = yes }
						pam_place_first_as_powerful_effect = { VALUE = pam_papabile_place_first_powerful_value }
					}
					else_if = {
						limit = { scope:pam_papabile_gold_option = yes }
						pam_increase_papabile_score_effect = { VALUE = pam_papabile_gold_option_score_value }
					}
					else = {
						pam_increase_papabile_score_effect = { VALUE = pam_papabile_base_score_value }
					}
				}
			}
		}
		scope:recipient = {
			if = {
				limit = {
					this != scope:actor
					is_ai = no
				}
				hidden_effect = {
					send_interface_toast = {
						type = event_toast_effect_good
						title = increase_papabile_score_interaction_toast
						left_icon = scope:recipient
						right_icon = scope:actor
						show_as_tooltip = {
							if = {
								limit = { scope:pam_papabile_place_first_option = yes }
								pam_place_first_as_powerful_effect = { VALUE = pam_papabile_place_first_powerful_value }
							}
							else_if = {
								limit = { scope:pam_papabile_gold_option = yes }
								pam_increase_papabile_score_effect = { VALUE = pam_papabile_gold_option_score_value }
							}
							else = {
								pam_increase_papabile_score_effect = { VALUE = pam_papabile_base_score_value }
							}
						}
					}
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = family
		max = 5
	}

	ai_targets = {
		ai_recipients = dynasty
		max = 5
	}

	ai_targets = {
		ai_recipients = self
		ai_recipients = puppets
		ai_recipients = spouses
		ai_recipients = papabile
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 72
		duchy = 36
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = 1000
			scope:recipient = scope:actor
		}

		modifier = {
			add = 100
			OR = {
				is_close_or_extended_family_of = scope:recipient
				scope:recipient.puppeteer ?= this
				has_relation_friend = scope:recipient
				has_relation_lover = scope:recipient
			}
		}

		modifier = {
			add = 50
			is_spouse_of = scope:recipient
		}

		modifier = {
			add = 25
			exists = scope:recipient.dynasty
			scope:actor.dynasty ?= scope:recipient.dynasty
		}

		modifier = {
			add = -25
			scope:actor = { has_trait = cynical }
		}

		modifier = {
			add = -25
			scope:actor = { has_trait = greedy }
		}

		modifier = { # A candidate of another rite is a rival faction's champion, not ours to elevate
			add = -60
			scope:recipient != scope:actor
			scope:actor = { rite != scope:recipient.rite }
		}
		
		modifier = {
			factor = 0
			scope:actor = { has_relation_rival = scope:recipient }
		}
	}
}

# Reform a patroned monastic order's tenet or rite
pam_reform_order_interaction = {
	category = interaction_category_religion
	icon = reform_order
	interface_priority = 41
	common_interaction = yes
	
	cooldown_against_recipient = { years = 5 }

	use_diplomatic_range = no
	ai_maybe = no
	popup_on_receive = yes
	greeting = negative
	notification_text = pam_reform_order_interaction_notification
	desc = pam_reform_order_interaction_desc
	
	is_available = {
		has_pam_dlc_trigger = yes
		is_adult = yes
	}

	is_shown = {
		scope:actor = {
			any_patroned_holy_order = {
				leader = scope:recipient
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_imprisoned = no
			is_incapable = no
		}
		scope:recipient = {
			is_imprisoned = no
			is_incapable = no
		}
		custom_tooltip = {
			text = pam_reform_order_is_valid_showing_failures_only_tt
			scope:actor = {
				OR = {
					rite != scope:recipient.rite
					any_personal_tenet = {
						NOT = { scope:recipient.holy_order.order_tenet ?= this }
					}
				}
			}
		}
	}

	send_options_exclusive = yes

	auto_accept = {
		custom_description = {
			text = pam_reform_order_puppet_acceptance_reason
			scope:recipient.puppeteer ?= scope:actor
		}
	}

	ai_accept = {
		base = -25
		opinion_modifier = {
			opinion_target = scope:actor
			multiplier = 0.5
		}
		modifier = {
			add = 25
			scope:recipient = { has_trait = humble }
			desc = pam_reform_order_humble_reason
		}
		modifier = {
			add = -25
			scope:recipient = { has_trait = ambitious }
			desc = pam_reform_order_ambitious_reason
		}
		modifier = {
			add = -25
			scope:recipient = { has_trait = stubborn }
			desc = pam_reform_order_stubborn_reason
		}
	}

	can_send = {
		OR = {
			custom_tooltip = {
				text = pam_reform_order_select_tenet_tt
				pam_evangelize_personal_tenet_send_option_selected_trigger = yes
			}
			scope:recipient.rite != scope:actor.rite
		}
	}

	## Extra indentation to collapse all send_options at once
	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_aniconism }
		}
		flag = tenet_aniconism
		localization = pam_evangelize_tenet_aniconism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_alexandrian_catechism }
		}
		flag = tenet_alexandrian_catechism
		localization = pam_evangelize_tenet_alexandrian_catechism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_armed_pilgrimages }
		}
		flag = tenet_armed_pilgrimages
		localization = pam_evangelize_tenet_armed_pilgrimages
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_carnal_exaltation }
		}
		flag = tenet_carnal_exaltation
		localization = pam_evangelize_tenet_carnal_exaltation
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_communal_identity }
		}
		flag = tenet_communal_identity
		localization = pam_evangelize_tenet_communal_identity
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_communion }
		}
		flag = tenet_communion
		localization = pam_evangelize_tenet_communion
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_consolamentum }
		}
		flag = tenet_consolamentum
		localization = pam_evangelize_tenet_consolamentum
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_divine_marriage }
		}
		flag = tenet_divine_marriage
		localization = pam_evangelize_tenet_divine_marriage
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_gnosticism }
		}
		flag = tenet_gnosticism
		localization = pam_evangelize_tenet_gnosticism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_mendicant_preachers }
		}
		flag = tenet_mendicant_preachers
		localization = pam_evangelize_tenet_mendicant_preachers
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_pacifism }
		}
		flag = tenet_pacifism
		localization = pam_evangelize_tenet_pacifism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_pentarchy }
		}
		flag = tenet_pentarchy
		localization = pam_evangelize_tenet_pentarchy
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_unrelenting_faith }
		}
		flag = tenet_unrelenting_faith
		localization = pam_evangelize_tenet_unrelenting_faith
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_vows_of_poverty }
		}
		flag = tenet_vows_of_poverty
		localization = pam_evangelize_tenet_vows_of_poverty
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_pastoral_isolation }
		}
		flag = tenet_pastoral_isolation
		localization = pam_evangelize_tenet_pastoral_isolation
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_adaptive }
		}
		flag = tenet_adaptive
		localization = pam_evangelize_tenet_adaptive
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_esotericism }
		}
		flag = tenet_esotericism
		localization = pam_evangelize_tenet_esotericism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_legalism }
		}
		flag = tenet_legalism
		localization = pam_evangelize_tenet_legalism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_literalism }
		}
		flag = tenet_literalism
		localization = pam_evangelize_tenet_literalism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_reincarnation }
		}
		flag = tenet_reincarnation
		localization = pam_evangelize_tenet_reincarnation
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_religious_legal_pronouncements }
		}
		flag = tenet_religious_legal_pronouncements
		localization = pam_evangelize_tenet_religious_legal_pronouncements
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_struggle_submission }
		}
		flag = tenet_struggle_submission
		localization = pam_evangelize_tenet_struggle_submission
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_false_conversion_sanction }
		}
		flag = tenet_false_conversion_sanction
		localization = pam_evangelize_tenet_false_conversion_sanction
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_tax_nonbelievers }
		}
		flag = tenet_tax_nonbelievers
		localization = pam_evangelize_tenet_tax_nonbelievers
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_asceticism }
		}
		flag = tenet_asceticism
		localization = pam_evangelize_tenet_asceticism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_bhakti }
		}
		flag = tenet_bhakti
		localization = pam_evangelize_tenet_bhakti
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_dharmic_pacifism }
		}
		flag = tenet_dharmic_pacifism
		localization = pam_evangelize_tenet_dharmic_pacifism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_inner_journey }
		}
		flag = tenet_inner_journey
		localization = pam_evangelize_tenet_inner_journey
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_ritual_hospitality }
		}
		flag = tenet_ritual_hospitality
		localization = pam_evangelize_tenet_ritual_hospitality
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_adorcism }
		}
		flag = tenet_adorcism
		localization = pam_evangelize_tenet_adorcism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_ancestor_worship }
		}
		flag = tenet_ancestor_worship
		localization = pam_evangelize_tenet_ancestor_worship
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_astrology }
		}
		flag = tenet_astrology
		localization = pam_evangelize_tenet_astrology
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_hedonistic }
		}
		flag = tenet_hedonistic
		localization = pam_evangelize_tenet_hedonistic
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_human_sacrifice }
		}
		flag = tenet_human_sacrifice
		localization = pam_evangelize_tenet_human_sacrifice
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_mystical_birthright }
		}
		flag = tenet_mystical_birthright
		localization = pam_evangelize_tenet_mystical_birthright
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_ritual_celebrations }
		}
		flag = tenet_ritual_celebrations
		localization = pam_evangelize_tenet_ritual_celebrations
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_sacred_childbirth }
		}
		flag = tenet_sacred_childbirth
		localization = pam_evangelize_tenet_sacred_childbirth
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_sanctity_of_nature }
		}
		flag = tenet_sanctity_of_nature
		localization = pam_evangelize_tenet_sanctity_of_nature
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_sun_worship }
		}
		flag = tenet_sun_worship
		localization = pam_evangelize_tenet_sun_worship
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_warmonger }
		}
		flag = tenet_warmonger
		localization = pam_evangelize_tenet_warmonger
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_gruesome_festivals }
		}
		flag = tenet_gruesome_festivals
		localization = pam_evangelize_tenet_gruesome_festivals
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_cthonic_redoubts }
		}
		flag = tenet_cthonic_redoubts
		localization = pam_evangelize_tenet_cthonic_redoubts
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_household_gods }
		}
		flag = tenet_household_gods
		localization = pam_evangelize_tenet_household_gods
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_sinitic_syncretism }
		}
		flag = tenet_sinitic_syncretism
		localization = pam_evangelize_tenet_sinitic_syncretism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_eastern_syncretism }
		}
		flag = tenet_eastern_syncretism
		localization = pam_evangelize_tenet_eastern_syncretism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_unreformed_syncretism }
		}
		flag = tenet_unreformed_syncretism
		localization = pam_evangelize_tenet_unreformed_syncretism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_christian_syncretism }
		}
		flag = tenet_christian_syncretism
		localization = pam_evangelize_tenet_christian_syncretism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_islamic_syncretism }
		}
		flag = tenet_islamic_syncretism
		localization = pam_evangelize_tenet_islamic_syncretism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_jewish_syncretism }
		}
		flag = tenet_jewish_syncretism
		localization = pam_evangelize_tenet_jewish_syncretism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_exaltation_of_pain }
		}
		flag = tenet_exaltation_of_pain
		localization = pam_evangelize_tenet_exaltation_of_pain
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_natural_primitivism }
		}
		flag = tenet_natural_primitivism
		localization = pam_evangelize_tenet_natural_primitivism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_pursuit_of_power }
		}
		flag = tenet_pursuit_of_power
		localization = pam_evangelize_tenet_pursuit_of_power
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_ritual_cannibalism }
		}
		flag = tenet_ritual_cannibalism
		localization = pam_evangelize_tenet_ritual_cannibalism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_sacred_shadows }
		}
		flag = tenet_sacred_shadows
		localization = pam_evangelize_tenet_sacred_shadows
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_polyamory }
		}
		flag = tenet_polyamory
		localization = pam_evangelize_tenet_polyamory
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_sacrificial_ceremonies }
		}
		flag = tenet_sacrificial_ceremonies
		localization = pam_evangelize_tenet_sacrificial_ceremonies
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_megaliths }
		}
		flag = tenet_megaliths
		localization = pam_evangelize_tenet_megaliths_name
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_fp3_fedayeen }
		}
		flag = tenet_fp3_fedayeen
		localization = pam_evangelize_tenet_fp3_fedayeen
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_communal_possessions }
		}
		flag = tenet_communal_possessions
		localization = pam_evangelize_tenet_communal_possessions
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_pure_land }
		}
		flag = tenet_pure_land
		localization = pam_evangelize_tenet_pure_land
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_no_mind }
		}
		flag = tenet_no_mind
		localization = pam_evangelize_tenet_no_mind
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_mountain_worship }
		}
		flag = tenet_mountain_worship
		localization = pam_evangelize_tenet_mountain_worship
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_extinction_of_dharma }
		}
		flag = tenet_extinction_of_dharma
		localization = pam_evangelize_tenet_extinction_of_dharma
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_cranial_trophies }
		}
		flag = tenet_cranial_trophies
		localization = pam_evangelize_tenet_cranial_trophies
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_pursuit_of_knowledge }
		}
		flag = tenet_pursuit_of_knowledge
		localization = pam_evangelize_tenet_pursuit_of_knowledge
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_benevolent_governance }
		}
		flag = tenet_benevolent_governance
		localization = pam_evangelize_tenet_benevolent_governance
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_filial_piety }
		}
		flag = tenet_filial_piety
		localization = pam_evangelize_tenet_filial_piety
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_harmonious_society }
		}
		flag = tenet_harmonious_society
		localization = pam_evangelize_tenet_harmonious_society
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_sacred_destruction }
		}
		flag = tenet_sacred_destruction
		localization = pam_evangelize_tenet_sacred_destruction
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_preservation }
		}
		flag = tenet_preservation
		localization = pam_evangelize_tenet_preservation
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_takamin }
		}
		flag = tenet_takamin
		localization = pam_evangelize_tenet_takamin
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_peace_of_god }
		}
		flag = tenet_peace_of_god
		localization = pam_evangelize_tenet_peace_of_god
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_dulia }
		}
		flag = tenet_dulia
		localization = pam_evangelize_tenet_dulia
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_transubstantiation }
		}
		flag = tenet_transubstantiation
		localization = pam_evangelize_tenet_transubstantiation
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_ora_et_labora }
		}
		flag = tenet_ora_et_labora
		localization = pam_evangelize_tenet_ora_et_labora
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_hyperdulia }
		}
		flag = tenet_hyperdulia
		localization = pam_evangelize_tenet_hyperdulia
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_simony }
		}
		flag = tenet_simony
		localization = pam_evangelize_tenet_simony
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_monophysitism }
		}
		flag = tenet_monophysitism
		localization = pam_evangelize_tenet_monophysitism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_acts_of_apostles }
		}
		flag = tenet_acts_of_apostles
		localization = pam_evangelize_tenet_acts_of_apostles
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_purgatory }
		}
		flag = tenet_purgatory
		localization = pam_evangelize_tenet_purgatory
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_be_fruitful_and_multiply }
		}
		flag = tenet_be_fruitful_and_multiply
		localization = pam_evangelize_tenet_be_fruitful_and_multiply
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_apostolic_succession }
		}
		flag = tenet_apostolic_succession
		localization = pam_evangelize_tenet_apostolic_succession
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_confession }
		}
		flag = tenet_confession
		localization = pam_evangelize_tenet_confession
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_original_sin }
		}
		flag = tenet_original_sin
		localization = pam_evangelize_tenet_original_sin
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_celestial_hierarchy }
		}
		flag = tenet_celestial_hierarchy
		localization = pam_evangelize_tenet_celestial_hierarchy
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_miles_christi }
		}
		flag = tenet_miles_christi
		localization = pam_evangelize_tenet_miles_christi
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_philanthropia }
		}
		flag = tenet_philanthropia
		localization = pam_evangelize_tenet_philanthropia
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_scholasticism }
		}
		flag = tenet_scholasticism
		localization = pam_evangelize_tenet_scholasticism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_adoptionism }
		}
		flag = tenet_adoptionism
		localization = pam_evangelize_tenet_adoptionism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_love_thy_neighbour }
		}
		flag = tenet_love_thy_neighbour
		localization = pam_evangelize_tenet_love_thy_neighbour
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_divine_liturgy }
		}
		flag = tenet_divine_liturgy
		localization = pam_evangelize_tenet_divine_liturgy
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_miaphysitism }
		}
		flag = tenet_miaphysitism
		localization = pam_evangelize_tenet_miaphysitism
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_hesychasm }
		}
		flag = tenet_hesychasm
		localization = pam_evangelize_tenet_hesychasm
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_anachoresis }
		}
		flag = tenet_anachoresis
		localization = pam_evangelize_tenet_anachoresis
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_mortification_of_the_flesh }
		}
		flag = tenet_mortification_of_the_flesh
		localization = pam_evangelize_tenet_mortification_of_the_flesh
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_holy_myron }
		}
		flag = tenet_holy_myron
		localization = pam_evangelize_tenet_holy_myron
		starts_enabled = { always = yes }
	}

	send_option = {
		is_shown = {
			pam_reform_order_tenet_option_shown_trigger = { TENET = tenet_khachkar }
		}
		flag = tenet_khachkar
		localization = pam_evangelize_tenet_khachkar
		starts_enabled = { always = yes }
	}

	on_accept = {
		pam_reform_order_effect = yes
	}
}

# Evangelize Personal Tenet Interaction
# The actor spreads their own Personal Tenet to a subject or courtier, increases that tenet's popularity
pam_evangelize_personal_tenet_interaction = {
	category = interaction_category_religion
	icon = evangelize_personal_tenet
	interface_priority = 40
	common_interaction = yes

	use_diplomatic_range = yes
	ai_maybe = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes
	can_send_despite_rejection = yes
	greeting = positive
	notification_text = pam_evangelize_personal_tenet_interaction_notification

	is_available = {
		is_available_quick = {
			ai = no
			adult = yes
			advanced_ruler = yes
		}
		OR = {
			is_clergy = yes
			has_theological_agent_puppet_trigger = yes
		}
	}
	#Use hook
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
			scope:recipient = {
				NOT = { is_imprisoned_by = scope:actor }
			}
		}
		flag = hook
		localization = SCHEME_HOOK
		starts_enabled = { always = yes }
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
		}
	}

	ai_accept = {
		base = -20
		religion_sway_to_rite_default_modifier = yes
		modifier = { # More likely for secular rulers to accept during instability
			add = 20
			situation:the_christian_church ?= {
				OR = {
					situation_participant_group:christian_regular_main_power_rulers = {
						participant_group_has_character = scope:recipient
						has_participant_group_parameter = the_christian_church_easier_sway_to_rite
					}
					situation_participant_group:christian_regular_secondary_powers_rulers = {
						participant_group_has_character = scope:recipient
						has_participant_group_parameter = the_christian_church_easier_sway_to_rite
					}
				}
			}
			desc = CHRISTIAN_CHURCH_PHASE_REASON
		}
		modifier = {
			add = -50
			pam_evangelize_recipient_desires_selected_tenet_trigger = no
			desc = pam_evangelize_recipient_undesired_selected_tenet_reason
		}
		modifier = {
			add = -50
			pam_evangelize_selected_tenet_prohibited_trigger = yes
			desc = pam_evangelize_recipient_prohibited_selected_tenet_reason
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_value_1
			desc = ESTATE_EVANGELIZE_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_easier_evangelize_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_value_2
			desc = ESTATE_EVANGELIZE_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_easier_evangelize_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_value_3
			desc = ESTATE_EVANGELIZE_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_easier_evangelize_3
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_1
			desc = ESTATE_EVANGELIZE_HOMILIARY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_evangelize_homiliary_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_2
			desc = ESTATE_EVANGELIZE_HOMILIARY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_evangelize_homiliary_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_3
			desc = ESTATE_EVANGELIZE_HOMILIARY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_evangelize_homiliary_3
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_1
			desc = ESTATE_EVANGELIZE_ARCHIVES_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_evangelize_archives_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_2
			desc = ESTATE_EVANGELIZE_ARCHIVES_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_evangelize_archives_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_3
			desc = ESTATE_EVANGELIZE_ARCHIVES_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_evangelize_archives_3
				}
			}
		}
		ecclesiastical_domicile_cathedral_awe_modifier = yes
	}

	desc = pam_evangelize_personal_tenet_interaction_desc

	is_shown = {
		scope:recipient = {
			this != scope:actor
			faith ?= scope:actor.faith
			is_available_quick = {
				adult = yes
				advanced_ruler = yes
			}
		}
		scope:actor = {
			any_personal_tenet = {
				scope:recipient = {
					NOT = { has_personal_tenet = prev }
				}
			}
		}
	}

	cooldown_against_recipient = { years = 5 }

	cost = {
		piety = {
			value = minor_piety_value
			if = {
				limit = {
					scope:actor = { has_character_modifier = pam_doctrinal_clarity_modifier }
				}
				multiply = 0.5
			}
			if = {
				limit = {
					scope:puppet_or_actor ?= {
						domicile ?= { has_domicile_parameter = estate_cheaper_evangelize }
					}
				}
				multiply = ecclesiastical_domicile_cheaper_evangelize_mult
			}
			#no cost when forced from interaction
			if = {
				limit = {
					scope:holy_order_leader ?= scope:actor
					exists = scope:order_tenet
				}
				multiply = 0
			}
		}
	}

	can_send = {
		OR = {
			custom_tooltip = {
				text = pam_evangelize_select_personal_tenet_tt
				pam_evangelize_personal_tenet_send_option_selected_trigger = yes
			}
			#holy order interaction uses order tenet
			AND = {
				scope:holy_order_leader ?= scope:actor
				exists = scope:order_tenet
			}
		}
	}

	## Extra indentation to collapse all send_options at once
		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_aniconism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_aniconism }
			}
			flag = tenet_aniconism
			localization = pam_evangelize_tenet_aniconism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_alexandrian_catechism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_alexandrian_catechism }
			}
			flag = tenet_alexandrian_catechism
			localization = pam_evangelize_tenet_alexandrian_catechism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_armed_pilgrimages }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_armed_pilgrimages }
			}
			flag = tenet_armed_pilgrimages
			localization = pam_evangelize_tenet_armed_pilgrimages
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_carnal_exaltation }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_carnal_exaltation }
			}
			flag = tenet_carnal_exaltation
			localization = pam_evangelize_tenet_carnal_exaltation
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_communal_identity }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_communal_identity }
			}
			flag = tenet_communal_identity
			localization = pam_evangelize_tenet_communal_identity
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_communion }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_communion }
			}
			flag = tenet_communion
			localization = pam_evangelize_tenet_communion
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_consolamentum }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_consolamentum }
			}
			flag = tenet_consolamentum
			localization = pam_evangelize_tenet_consolamentum
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_divine_marriage }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_divine_marriage }
			}
			flag = tenet_divine_marriage
			localization = pam_evangelize_tenet_divine_marriage
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_gnosticism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_gnosticism }
			}
			flag = tenet_gnosticism
			localization = pam_evangelize_tenet_gnosticism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_mendicant_preachers }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_mendicant_preachers }
			}
			flag = tenet_mendicant_preachers
			localization = pam_evangelize_tenet_mendicant_preachers
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_pacifism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_pacifism }
			}
			flag = tenet_pacifism
			localization = pam_evangelize_tenet_pacifism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_pentarchy }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_pentarchy }
			}
			flag = tenet_pentarchy
			localization = pam_evangelize_tenet_pentarchy
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_unrelenting_faith }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_unrelenting_faith }
			}
			flag = tenet_unrelenting_faith
			localization = pam_evangelize_tenet_unrelenting_faith
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_vows_of_poverty }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_vows_of_poverty }
			}
			flag = tenet_vows_of_poverty
			localization = pam_evangelize_tenet_vows_of_poverty
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_pastoral_isolation }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_pastoral_isolation }
			}
			flag = tenet_pastoral_isolation
			localization = pam_evangelize_tenet_pastoral_isolation
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_adaptive }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_adaptive }
			}
			flag = tenet_adaptive
			localization = pam_evangelize_tenet_adaptive
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_esotericism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_esotericism }
			}
			flag = tenet_esotericism
			localization = pam_evangelize_tenet_esotericism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_legalism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_legalism }
			}
			flag = tenet_legalism
			localization = pam_evangelize_tenet_legalism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_literalism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_literalism }
			}
			flag = tenet_literalism
			localization = pam_evangelize_tenet_literalism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_reincarnation }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_reincarnation }
			}
			flag = tenet_reincarnation
			localization = pam_evangelize_tenet_reincarnation
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_religious_legal_pronouncements }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_religious_legal_pronouncements }
			}
			flag = tenet_religious_legal_pronouncements
			localization = pam_evangelize_tenet_religious_legal_pronouncements
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_struggle_submission }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_struggle_submission }
			}
			flag = tenet_struggle_submission
			localization = pam_evangelize_tenet_struggle_submission
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_false_conversion_sanction }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_false_conversion_sanction }
			}
			flag = tenet_false_conversion_sanction
			localization = pam_evangelize_tenet_false_conversion_sanction
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_tax_nonbelievers }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_tax_nonbelievers }
			}
			flag = tenet_tax_nonbelievers
			localization = pam_evangelize_tenet_tax_nonbelievers
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_asceticism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_asceticism }
			}
			flag = tenet_asceticism
			localization = pam_evangelize_tenet_asceticism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_bhakti }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_bhakti }
			}
			flag = tenet_bhakti
			localization = pam_evangelize_tenet_bhakti
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_dharmic_pacifism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_dharmic_pacifism }
			}
			flag = tenet_dharmic_pacifism
			localization = pam_evangelize_tenet_dharmic_pacifism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_inner_journey }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_inner_journey }
			}
			flag = tenet_inner_journey
			localization = pam_evangelize_tenet_inner_journey
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_ritual_hospitality }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_ritual_hospitality }
			}
			flag = tenet_ritual_hospitality
			localization = pam_evangelize_tenet_ritual_hospitality
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_adorcism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_adorcism }
			}
			flag = tenet_adorcism
			localization = pam_evangelize_tenet_adorcism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_ancestor_worship }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_ancestor_worship }
			}
			flag = tenet_ancestor_worship
			localization = pam_evangelize_tenet_ancestor_worship
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_astrology }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_astrology }
			}
			flag = tenet_astrology
			localization = pam_evangelize_tenet_astrology
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_hedonistic }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_hedonistic }
			}
			flag = tenet_hedonistic
			localization = pam_evangelize_tenet_hedonistic
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_human_sacrifice }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_human_sacrifice }
			}
			flag = tenet_human_sacrifice
			localization = pam_evangelize_tenet_human_sacrifice
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_mystical_birthright }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_mystical_birthright }
			}
			flag = tenet_mystical_birthright
			localization = pam_evangelize_tenet_mystical_birthright
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_ritual_celebrations }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_ritual_celebrations }
			}
			flag = tenet_ritual_celebrations
			localization = pam_evangelize_tenet_ritual_celebrations
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_sacred_childbirth }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_sacred_childbirth }
			}
			flag = tenet_sacred_childbirth
			localization = pam_evangelize_tenet_sacred_childbirth
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_sanctity_of_nature }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_sanctity_of_nature }
			}
			flag = tenet_sanctity_of_nature
			localization = pam_evangelize_tenet_sanctity_of_nature
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_sun_worship }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_sun_worship }
			}
			flag = tenet_sun_worship
			localization = pam_evangelize_tenet_sun_worship
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_warmonger }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_warmonger }
			}
			flag = tenet_warmonger
			localization = pam_evangelize_tenet_warmonger
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_gruesome_festivals }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_gruesome_festivals }
			}
			flag = tenet_gruesome_festivals
			localization = pam_evangelize_tenet_gruesome_festivals
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_cthonic_redoubts }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_cthonic_redoubts }
			}
			flag = tenet_cthonic_redoubts
			localization = pam_evangelize_tenet_cthonic_redoubts
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_household_gods }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_household_gods }
			}
			flag = tenet_household_gods
			localization = pam_evangelize_tenet_household_gods
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_sinitic_syncretism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_sinitic_syncretism }
			}
			flag = tenet_sinitic_syncretism
			localization = pam_evangelize_tenet_sinitic_syncretism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_eastern_syncretism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_eastern_syncretism }
			}
			flag = tenet_eastern_syncretism
			localization = pam_evangelize_tenet_eastern_syncretism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_unreformed_syncretism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_unreformed_syncretism }
			}
			flag = tenet_unreformed_syncretism
			localization = pam_evangelize_tenet_unreformed_syncretism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_christian_syncretism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_christian_syncretism }
			}
			flag = tenet_christian_syncretism
			localization = pam_evangelize_tenet_christian_syncretism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_islamic_syncretism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_islamic_syncretism }
			}
			flag = tenet_islamic_syncretism
			localization = pam_evangelize_tenet_islamic_syncretism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_jewish_syncretism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_jewish_syncretism }
			}
			flag = tenet_jewish_syncretism
			localization = pam_evangelize_tenet_jewish_syncretism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_exaltation_of_pain }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_exaltation_of_pain }
			}
			flag = tenet_exaltation_of_pain
			localization = pam_evangelize_tenet_exaltation_of_pain
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_natural_primitivism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_natural_primitivism }
			}
			flag = tenet_natural_primitivism
			localization = pam_evangelize_tenet_natural_primitivism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_pursuit_of_power }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_pursuit_of_power }
			}
			flag = tenet_pursuit_of_power
			localization = pam_evangelize_tenet_pursuit_of_power
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_ritual_cannibalism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_ritual_cannibalism }
			}
			flag = tenet_ritual_cannibalism
			localization = pam_evangelize_tenet_ritual_cannibalism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_sacred_shadows }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_sacred_shadows }
			}
			flag = tenet_sacred_shadows
			localization = pam_evangelize_tenet_sacred_shadows
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_polyamory }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_polyamory }
			}
			flag = tenet_polyamory
			localization = pam_evangelize_tenet_polyamory
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_sacrificial_ceremonies }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_sacrificial_ceremonies }
			}
			flag = tenet_sacrificial_ceremonies
			localization = pam_evangelize_tenet_sacrificial_ceremonies
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_megaliths }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_megaliths }
			}
			flag = tenet_megaliths
			localization = pam_evangelize_tenet_megaliths_name
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_fp3_fedayeen }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_fp3_fedayeen }
			}
			flag = tenet_fp3_fedayeen
			localization = pam_evangelize_tenet_fp3_fedayeen
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_communal_possessions }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_communal_possessions }
			}
			flag = tenet_communal_possessions
			localization = pam_evangelize_tenet_communal_possessions
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_pure_land }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_pure_land }
			}
			flag = tenet_pure_land
			localization = pam_evangelize_tenet_pure_land
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_no_mind }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_no_mind }
			}
			flag = tenet_no_mind
			localization = pam_evangelize_tenet_no_mind
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_mountain_worship }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_mountain_worship }
			}
			flag = tenet_mountain_worship
			localization = pam_evangelize_tenet_mountain_worship
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_extinction_of_dharma }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_extinction_of_dharma }
			}
			flag = tenet_extinction_of_dharma
			localization = pam_evangelize_tenet_extinction_of_dharma
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_cranial_trophies }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_cranial_trophies }
			}
			flag = tenet_cranial_trophies
			localization = pam_evangelize_tenet_cranial_trophies
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_pursuit_of_knowledge }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_pursuit_of_knowledge }
			}
			flag = tenet_pursuit_of_knowledge
			localization = pam_evangelize_tenet_pursuit_of_knowledge
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_benevolent_governance }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_benevolent_governance }
			}
			flag = tenet_benevolent_governance
			localization = pam_evangelize_tenet_benevolent_governance
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_filial_piety }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_filial_piety }
			}
			flag = tenet_filial_piety
			localization = pam_evangelize_tenet_filial_piety
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_harmonious_society }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_harmonious_society }
			}
			flag = tenet_harmonious_society
			localization = pam_evangelize_tenet_harmonious_society
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_sacred_destruction }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_sacred_destruction }
			}
			flag = tenet_sacred_destruction
			localization = pam_evangelize_tenet_sacred_destruction
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_preservation }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_preservation }
			}
			flag = tenet_preservation
			localization = pam_evangelize_tenet_preservation
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_takamin }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_takamin }
			}
			flag = tenet_takamin
			localization = pam_evangelize_tenet_takamin
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_peace_of_god }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_peace_of_god }
			}
			flag = tenet_peace_of_god
			localization = pam_evangelize_tenet_peace_of_god
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_dulia }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_dulia }
			}
			flag = tenet_dulia
			localization = pam_evangelize_tenet_dulia
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_transubstantiation }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_transubstantiation }
			}
			flag = tenet_transubstantiation
			localization = pam_evangelize_tenet_transubstantiation
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_ora_et_labora }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_ora_et_labora }
			}
			flag = tenet_ora_et_labora
			localization = pam_evangelize_tenet_ora_et_labora
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_hyperdulia }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_hyperdulia }
			}
			flag = tenet_hyperdulia
			localization = pam_evangelize_tenet_hyperdulia
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_simony }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_simony }
			}
			flag = tenet_simony
			localization = pam_evangelize_tenet_simony
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_monophysitism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_monophysitism }
			}
			flag = tenet_monophysitism
			localization = pam_evangelize_tenet_monophysitism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_acts_of_apostles }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_acts_of_apostles }
			}
			flag = tenet_acts_of_apostles
			localization = pam_evangelize_tenet_acts_of_apostles
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_purgatory }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_purgatory }
			}
			flag = tenet_purgatory
			localization = pam_evangelize_tenet_purgatory
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_be_fruitful_and_multiply }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_be_fruitful_and_multiply }
			}
			flag = tenet_be_fruitful_and_multiply
			localization = pam_evangelize_tenet_be_fruitful_and_multiply
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_apostolic_succession }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_apostolic_succession }
			}
			flag = tenet_apostolic_succession
			localization = pam_evangelize_tenet_apostolic_succession
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_confession }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_confession }
			}
			flag = tenet_confession
			localization = pam_evangelize_tenet_confession
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_original_sin }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_original_sin }
			}
			flag = tenet_original_sin
			localization = pam_evangelize_tenet_original_sin
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_celestial_hierarchy }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_celestial_hierarchy }
			}
			flag = tenet_celestial_hierarchy
			localization = pam_evangelize_tenet_celestial_hierarchy
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_miles_christi }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_miles_christi }
			}
			flag = tenet_miles_christi
			localization = pam_evangelize_tenet_miles_christi
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_philanthropia }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_philanthropia }
			}
			flag = tenet_philanthropia
			localization = pam_evangelize_tenet_philanthropia
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_scholasticism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_scholasticism }
			}
			flag = tenet_scholasticism
			localization = pam_evangelize_tenet_scholasticism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_adoptionism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_adoptionism }
			}
			flag = tenet_adoptionism
			localization = pam_evangelize_tenet_adoptionism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_love_thy_neighbour }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_love_thy_neighbour }
			}
			flag = tenet_love_thy_neighbour
			localization = pam_evangelize_tenet_love_thy_neighbour
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_divine_liturgy }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_divine_liturgy }
			}
			flag = tenet_divine_liturgy
			localization = pam_evangelize_tenet_divine_liturgy
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_miaphysitism }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_miaphysitism }
			}
			flag = tenet_miaphysitism
			localization = pam_evangelize_tenet_miaphysitism
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_hesychasm }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_hesychasm }
			}
			flag = tenet_hesychasm
			localization = pam_evangelize_tenet_hesychasm
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_anachoresis }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_anachoresis }
			}
			flag = tenet_anachoresis
			localization = pam_evangelize_tenet_anachoresis
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_mortification_of_the_flesh }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_mortification_of_the_flesh }
			}
			flag = tenet_mortification_of_the_flesh
			localization = pam_evangelize_tenet_mortification_of_the_flesh
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_holy_myron }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_holy_myron }
			}
			flag = tenet_holy_myron
			localization = pam_evangelize_tenet_holy_myron
			starts_enabled = { always = yes }
		}

		send_option = {
			is_shown = {
				pam_tenet_can_be_evangelized_trigger = { TENET = tenet_khachkar }
			}
			is_valid = {
				pam_evangelize_personal_tenet_send_option_valid_trigger = { TENET = tenet_khachkar }
			}
			flag = tenet_khachkar
			localization = pam_evangelize_tenet_khachkar
			starts_enabled = { always = yes }
		}

	auto_accept = no

	on_send = {
		#holy order interaction uses order tenet
		if = {
			limit = {
				scope:holy_order_leader ?= scope:actor
				exists = scope:order_tenet
			}
			scope:order_tenet = {
				save_scope_as = pam_evangelize_tenet
			}
		}
		else = {
			pam_save_selected_interaction_tenet_effect = yes
			scope:pam_selected_interaction_tenet = { save_scope_as = pam_evangelize_tenet }
		}
	}

	on_accept = {
		# Needed for character interaction interface to show a proper tooltip when send options are not selected
		if = {
			limit = {
				NOT = { exists = scope:pam_evangelize_tenet }
			}
			scope:recipient = {
				custom_tooltip = pam_evangelize_personal_tenet_interaction_tooltip
				custom_tooltip = pam_evangelize_personal_tenet_interaction_popularity_tooltip
			}
			scope:actor = {
				show_as_tooltip = {
					change_spiritual_fulfillment = miniscule_spiritual_fulfillment_value
				}
				if = {
					limit = {
						scope:hook = yes
						has_usable_hook = scope:recipient
					}
					show_as_tooltip = { use_hook = scope:recipient }
				}
				custom_tooltip = pam_evangelize_personal_tenet_interaction_prohibited_secret_tooltip
			}
		}
		else = {
			scope:actor = {
				send_interface_toast = {
					type = event_toast_effect_good
					title = pam_evangelize_personal_tenet_interaction_toast
					left_icon = scope:actor
					right_icon = scope:recipient
					pam_evangelize_personal_tenet_effect = yes
				}
			}
		}
	}
	on_decline = {
		if = {
			limit = {
				NOT = { exists = scope:pam_evangelize_tenet }
			}
			scope:actor = {
				change_spiritual_fulfillment = miniscule_spiritual_fulfillment_loss
				custom_tooltip = pam_evangelize_personal_tenet_interaction_prohibited_secret_tooltip
			}
		}
		else = {
			scope:actor = {
				show_as_tooltip = {
					pam_evangelize_personal_tenet_decline_effect = yes
				}
				send_interface_toast = {
					type = event_toast_effect_bad
					title = pam_evangelize_personal_tenet_interaction_toast_declined
					left_icon = scope:actor
					right_icon = scope:recipient
					pam_evangelize_personal_tenet_decline_effect = yes
				}
			}
		}
	}
}

# Players pick a tenet through send_options, and the AI only has the hook so on_send picks a random tenet
pam_ai_evangelize_personal_tenet_interaction = {
	category = interaction_category_religion
	icon = evangelize_personal_tenet
	interface_priority = 40
	hidden = yes

	use_diplomatic_range = yes
	ai_maybe = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes
	can_send_despite_rejection = yes
	greeting = positive
	notification_text = pam_evangelize_personal_tenet_interaction_notification

	#Use hook
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
			scope:recipient = {
				NOT = { is_imprisoned_by = scope:actor }
			}
		}
		flag = hook
		localization = SCHEME_HOOK
		starts_enabled = { always = yes }
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
		}
	}

	ai_accept = {
		base = -20
		religion_sway_to_rite_default_modifier = yes
		modifier = { # More likely for secular rulers to accept during instability
			add = 20
			situation:the_christian_church ?= {
				OR = {
					situation_participant_group:christian_regular_main_power_rulers = {
						participant_group_has_character = scope:recipient
						has_participant_group_parameter = the_christian_church_easier_sway_to_rite
					}
					situation_participant_group:christian_regular_secondary_powers_rulers = {
						participant_group_has_character = scope:recipient
						has_participant_group_parameter = the_christian_church_easier_sway_to_rite
					}
				}
			}
			desc = CHRISTIAN_CHURCH_PHASE_REASON
		}
		modifier = {
			add = -50
			pam_evangelize_recipient_desires_selected_tenet_trigger = no
			desc = pam_evangelize_recipient_undesired_selected_tenet_reason
		}
		modifier = {
			add = -50
			pam_evangelize_selected_tenet_prohibited_trigger = yes
			desc = pam_evangelize_recipient_prohibited_selected_tenet_reason
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_value_1
			desc = ESTATE_EVANGELIZE_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_easier_evangelize_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_value_2
			desc = ESTATE_EVANGELIZE_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_easier_evangelize_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_value_3
			desc = ESTATE_EVANGELIZE_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_easier_evangelize_3
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_1
			desc = ESTATE_EVANGELIZE_HOMILIARY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_evangelize_homiliary_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_2
			desc = ESTATE_EVANGELIZE_HOMILIARY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_evangelize_homiliary_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_3
			desc = ESTATE_EVANGELIZE_HOMILIARY_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_evangelize_homiliary_3
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_1
			desc = ESTATE_EVANGELIZE_ARCHIVES_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_evangelize_archives_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_2
			desc = ESTATE_EVANGELIZE_ARCHIVES_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_evangelize_archives_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_3
			desc = ESTATE_EVANGELIZE_ARCHIVES_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_evangelize_archives_3
				}
			}
		}
		ecclesiastical_domicile_cathedral_awe_modifier = yes
	}

	ai_targets = {
		ai_recipients = family
		max = 5
	}

	ai_targets = {
		ai_recipients = courtiers
		max = 5
	}

	ai_targets = {
		ai_recipients = vassals
		ai_recipients = tributaries
		ai_recipients = clerical_region_rulers_in_realm
		ai_recipients = rulers_in_clerical_region
		ai_recipients = puppets
		ai_recipients = subordinates
		ai_recipients = councillors
		max = 20
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	# Four times slower than usual: each firing pays a one-off-sized popularity gain
	ai_frequency_by_tier = {
		barony = 0
		county = 240
		duchy = 120
		kingdom = 48
		empire = 48
		hegemony = 48
	}

	ai_will_do = {
		base = 25
		modifier = {
			scope:hook = yes
			add = 50
		}
		modifier = {
			add = 50
			scope:actor = {
				has_trait = zealous
			}
		}
		modifier = {
			add = -50
			scope:actor = {
				has_trait = cynical
			}
		}
		modifier = {
			add = 20
			scope:actor = {
				is_allied_to = scope:recipient
			}
		}
		modifier = {
			add = 10
			scope:actor = {
				has_relation_best_friend = scope:recipient
			}
		}
		modifier = {
			add = 10
			scope:recipient = {
				opinion = {
					target = scope:actor
					value >= 65
				}
			}
		}
		modifier = { # More likely to happen during Instability
			add = 15
			scope:actor.religion = religion:christianity_religion
			situation:the_christian_church ?= {
				has_situation_top_phase_parameter = the_christian_church_easier_sway_to_rite
			}
		}
		modifier = { # More likely if the government is religious
			add = 50
			scope:actor = {
				government_is_religious_trigger = yes
			}
		}
		modifier = { # Heresiarchs are able to spread their rites easily
			add = 1000
			scope:actor = {
				OR = {
					has_trait = heresiarch
					has_trait = herald
				}
			}
		}
		modifier = { # Try to rigorously convert your heir so all efforts won't go to waste on succession
			add = 100
			scope:recipient = {
				is_primary_heir_of = scope:actor
			}
		}
		modifier = { # More likely against close family members
			add = 50
			scope:recipient = {
				is_close_family_of = scope:actor
			}
		}
		modifier = { # Prefer higher tiers
			add = scope:recipient.highest_held_title_tier
		}
		modifier = { # Converts clinging to a Popular belief are the ones worth luring away
			add = -20
			scope:recipient = {
				NOT = {
					any_personal_tenet = {
						pam_tenet_is_at_least_popular_trigger = { CHARACTER = scope:recipient }
					}
				}
			}
		}
	}
	desc = pam_evangelize_personal_tenet_interaction_desc

	# Actor-only gating (cheap, runs often for AI/menu).
	is_available = {
		is_available_quick = {
			ai = yes
			adult = yes
			advanced_ruler = yes
		}
		is_clergy = yes # The puppet route is reserved for players; the AI preaches through its own clergy
		faith ?= { has_tenet_popularity_trigger = yes }
		has_pam_dlc_trigger = yes
		# Actor scope: drop out in is_available once every tenet is already Very Popular
		save_temporary_scope_as = pam_evangelize_popularity_actor
		any_personal_tenet = {
			save_temporary_scope_as = pam_evangelize_tenet_check
			scope:pam_evangelize_popularity_actor = {
				pam_evangelize_tenet_below_very_popular_trigger = yes
			}
		}
	}

	is_shown = {
		scope:actor = {
			any_personal_tenet = {
				save_temporary_scope_as = pam_evangelize_tenet_check
				scope:recipient = {
					NOT = { has_personal_tenet = scope:pam_evangelize_tenet_check }
				}
				scope:actor = {
					pam_evangelize_tenet_below_very_popular_trigger = yes
				}
			}
		}
		scope:recipient = {
			this != scope:actor
			faith ?= scope:actor.faith
			is_available_quick = {
				adult = yes
				advanced_ruler = yes
			}
		}
	}

	cooldown_against_recipient = { years = 5 }

	cost = {
		piety = {
			value = minor_piety_value
			if = {
				limit = {
					scope:puppet_or_actor ?= {
						domicile ?= { has_domicile_parameter = estate_cheaper_evangelize }
					}
				}
				multiply = ecclesiastical_domicile_cheaper_evangelize_mult
			}
		}
	}

	auto_accept = no

	on_send = {
		# A random tenet uses the same two is_shown checks, so there is always one left to pick
		scope:actor = {
			random_personal_tenet = {
				limit = {
					save_temporary_scope_as = pam_evangelize_tenet_check
					scope:recipient = {
						NOT = { has_personal_tenet = scope:pam_evangelize_tenet_check }
					}
					scope:actor = {
						pam_evangelize_tenet_below_very_popular_trigger = yes
					}
				}
				save_scope_as = pam_evangelize_tenet
			}
		}

	}
	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = pam_evangelize_personal_tenet_interaction_toast
				left_icon = scope:actor
				right_icon = scope:recipient
				pam_evangelize_personal_tenet_effect = yes
			}
		}
	}
	on_decline = {
		scope:actor = {
			show_as_tooltip = {
				pam_evangelize_personal_tenet_decline_effect = yes
			}
			send_interface_toast = {
				type = event_toast_effect_bad
				title = pam_evangelize_personal_tenet_interaction_toast_declined
				left_icon = scope:actor
				right_icon = scope:recipient
				pam_evangelize_personal_tenet_decline_effect = yes
			}
		}
	}
}

# HoF only, on HoRs
# Replace a doctrine of other rite in your faith by your rite's in same group
pam_reaffirm_doctrine_interaction = {
	category = interaction_category_religion
	icon = reaffirm_doctrine
	interface_priority = 40
	common_interaction = yes

	use_diplomatic_range = yes
	ai_maybe = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes
	can_send_despite_rejection = yes
	greeting = positive
	notification_text = pam_reaffirm_doctrine_interaction_notification
	desc = pam_reaffirm_doctrine_interaction_desc

	is_available = {
		faith.religious_head ?= this
		is_available_adult = yes
	}
	#Use hook
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
			scope:recipient = {
				NOT = { is_imprisoned_by = scope:actor }
			}
		}
		flag = hook
		localization = SCHEME_HOOK
		starts_enabled = { always = yes }
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
		}
	}

	ai_accept = {
		base = -100

		modifier = {
			add = {
				value = scope:actor.piety_level
				subtract = scope:recipient.piety_level
				multiply = 15
				min = 0
			}
			scope:actor.piety_level > scope:recipient.piety_level
			desc = spiritual_counsel_ai_priest_pious
		}
		modifier = { # Heralds are more convincing
			add = 75
			scope:puppet_or_actor ?= {
				has_trait = herald
			}
			desc = I_HAVE_HERALD_TRAIT
		}
		modifier = {
			add = -75
			scope:recipient = {
				has_trait = herald
			}
			desc = I_HAVE_HERALD_TRAIT
		}
		modifier = { # Heresiarchs are more convincing
			add = 30
			scope:puppet_or_actor ?= {
				has_trait = heresiarch
			}
			desc = I_HAVE_HERESIARCH_TRAIT
		}
		modifier = {
			add = -100
			scope:recipient = {
				has_trait = heresiarch
			}
			desc = ASK_FOR_CONVERSION_RECIPIENT_IS_HERESIARCH
		}
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:puppet_or_actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		modifier = {
			add = 20
			scope:recipient = {
				is_close_family_of = scope:puppet_or_actor
			}
			desc = CLOSE_FAMILY_REASON
		}

		modifier = {
			add = 10
			scope:recipient = {
				NOT = { is_close_family_of = scope:puppet_or_actor }
				is_extended_family_of = scope:puppet_or_actor
			}
			desc = EXTENDED_FAMILY_REASON
		}
		modifier = {
			scope:recipient = {
				has_relation_lover = scope:puppet_or_actor
			}
			add = {
				value = 25
			}
			desc = WE_ARE_LOVERS
		}
		modifier = {
			scope:recipient = {
				has_relation_friend = scope:puppet_or_actor
			}
			add = {
				value = 25
			}
			desc = WE_ARE_FRIENDS
		}
		modifier = {
			add = -40
			scope:recipient = {
				has_trait = zealous
			}
			desc = INTERACTION_ZEALOUS
		}
		modifier = {
			add = {
				value = scope:puppet_or_actor.learning
				subtract = scope:recipient.learning
			}
			desc = ASK_FOR_CONVERSION_RECIPIENT_LEARNING
		}
		modifier = {
			add = intimidated_halved_reason_value
			scope:puppet_or_actor ?= {
				is_landless_adventurer = no
			}
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:puppet_or_actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = cowed_halved_reason_value
			scope:puppet_or_actor ?= {
				is_landless_adventurer = no
			}
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:puppet_or_actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		modifier = { # Title tier difference
			add = {
				value = scope:puppet_or_actor.highest_held_title_tier
				subtract = scope:recipient.highest_held_title_tier
				multiply = 20
			}
			scope:puppet_or_actor ?= {
				OR = {
					highest_held_title_tier > scope:recipient.highest_held_title_tier
					highest_held_title_tier < scope:recipient.highest_held_title_tier
				}
			}
			scope:recipient = {
				trigger_if = { # If clerical region holder, works against any ruler
					limit = {
						scope:puppet_or_actor ?= {
							any_held_title = { has_clerical_region = yes }
						}
					}
					is_ruler = yes
				}
				trigger_else = { # If secular holder, only works against vassals
					limit = {
						scope:puppet_or_actor ?= {
							NOT = {
								any_held_title = { has_clerical_region = yes }
							}
						}
					}
					is_vassal_of = scope:puppet_or_actor
				}
			}
			desc = RELATIVE_TITLE_TIER_REASON
		}
		modifier = { # More likely if the recipient's capital is already of our rite
			add = 15
			scope:recipient = {
				is_ruler = yes
				capital_county.rite = scope:puppet_or_actor.rite
			}
			desc = THEY_HAVE_CAPITAL_WITH_SAME_RITE_REASON
		}
		modifier = { # We don't share the same realm (secular players only)
			add = -20
			scope:puppet_or_actor ?= {
				is_ai = no
				any_held_title = { has_clerical_region = no }
				this.top_liege != scope:recipient.top_liege
			}
			desc = not_same_realm_value_tt
		}
		modifier = { # More likely for secular rulers to accept during instability
			add = 10
			situation:the_christian_church ?= {
				OR = {
					situation_participant_group:christian_regular_main_power_rulers = {
						participant_group_has_character = scope:recipient
						has_participant_group_parameter = the_christian_church_easier_sway_to_rite
					}
					situation_participant_group:christian_regular_secondary_powers_rulers = {
						participant_group_has_character = scope:recipient
						has_participant_group_parameter = the_christian_church_easier_sway_to_rite
					}
				}
			}
			desc = CHRISTIAN_CHURCH_PHASE_REASON
		}
		modifier = {
			add = -1000
			switch = {
				trigger = yes
				scope:doctrine_bastardry_all = {
					scope:recipient = { has_trait = bastard }
				}
				scope:doctrine_homosexuality_crime = {
					scope:recipient = {
						OR = {
							is_attracted_to_gender_of = this
							is_sodomite_trigger = yes
						}
					}
				}
				scope:doctrine_homosexuality_shunned = {
					scope:recipient = {
						OR = {
							is_attracted_to_gender_of = this
							is_sodomite_trigger = yes
						}
						NOT = { rite = { rite_has_doctrine = doctrine_homosexuality_crime } }
					}
				}
				scope:doctrine_deviancy_crime = {
					scope:recipient = { is_deviant_trigger = yes }
				}
				scope:doctrine_deviancy_shunned = {
					scope:recipient = {
						is_deviant_trigger = yes
						NOT = { rite = { rite_has_doctrine = doctrine_deviancy_crime } }
					}
				}
				scope:doctrine_adultery_men_shunned = {
					scope:recipient = {
						is_female = no
						is_adulterer_or_fornicator_trigger = yes
						NOT = { rite = { rite_has_doctrine = doctrine_adultery_men_crime } }
					}
				}
				scope:doctrine_adultery_men_crime = {
					scope:recipient = {
						is_female = no
						is_adulterer_or_fornicator_trigger = yes
					}
				}
				scope:doctrine_adultery_women_shunned = {
					scope:recipient = {
						is_female = yes
						is_adulterer_or_fornicator_trigger = yes
						NOT = { rite = { rite_has_doctrine = doctrine_adultery_women_crime } }
					}
				}
				scope:doctrine_adultery_women_crime = {
					scope:recipient = {
						is_female = yes
						is_adulterer_or_fornicator_trigger = yes
					}
				}
				scope:doctrine_witchcraft_crime = {
					scope:recipient = { is_witch_trigger = yes }
				}
				scope:doctrine_witchcraft_shunned = {
					scope:recipient = {
						is_witch_trigger = yes
						NOT = { rite = { rite_has_doctrine = doctrine_witchcraft_crime } }
					}
				}

				scope:doctrine_kinslaying_any_dynasty_member_crime = {
					scope:recipient = { pam_reaffirm_doctrine_kinslayer_decline_trigger = yes }
				}
				scope:doctrine_kinslaying_extended_family_crime = {
					scope:recipient = { pam_reaffirm_doctrine_kinslayer_decline_trigger = yes }
				}
				scope:doctrine_kinslaying_close_kin_crime = {
					scope:recipient = { pam_reaffirm_doctrine_kinslayer_decline_trigger = yes }
				}
				scope:doctrine_kinslaying_shunned = {
					scope:recipient = {
						rite = { rite_has_doctrine = doctrine_kinslaying_accepted }
						OR = {
							has_trait = kinslayer
							any_secret = {
								type = secret_murder
								secret_target = { save_temporary_scope_as = target }
								scope:recipient = {
									murdering_character_is_kinslaying_in_rite_trigger = {
										CHARACTER = scope:target
										RITE = scope:actor.rite
									}
								}
							}
						}
					}
				}

				scope:doctrine_gender_male_dominated = {
					scope:recipient = { is_female = yes }
				}
				scope:doctrine_gender_female_dominated = {
					scope:recipient = { is_female = no }
				}

				scope:doctrine_consanguinity_dynastic = {
					scope:recipient = { pam_reaffirm_doctrine_consanguinity_decline_trigger = yes }
				}
				scope:doctrine_consanguinity_restricted = {
					scope:recipient = { pam_reaffirm_doctrine_consanguinity_decline_trigger = yes }
				}
				scope:doctrine_consanguinity_cousins = {
					scope:recipient = { pam_reaffirm_doctrine_consanguinity_decline_trigger = yes }
				}
				scope:doctrine_consanguinity_aunt_nephew_and_uncle_niece = {
					scope:recipient = { pam_reaffirm_doctrine_consanguinity_decline_trigger = yes }
				}

				scope:doctrine_clerical_gender_male_only = {
					scope:recipient = { is_female = yes }
				}
				scope:doctrine_clerical_gender_female_only = {
					scope:recipient = { is_female = no }
				}
				scope:doctrine_clerical_marriage_disallowed = {
					scope:recipient = { is_married = yes }
				}
				scope:doctrine_pilgrimage_forbidden = {
					scope:recipient = { has_trait = pilgrim }
				}
				fallback = { always = no }
			}
			desc = pam_reaffirm_doctrine_recipient_undesired_reason
		}
		modifier = {
			add = 100
			switch = {
				trigger = yes
				scope:doctrine_homosexuality_accepted = {
					scope:recipient = {
						OR = {
							is_attracted_to_gender_of = this
							is_sodomite_trigger = yes
						}
					}
				}
				scope:doctrine_homosexuality_shunned = {
					scope:recipient = {
						OR = {
							is_attracted_to_gender_of = this
							is_sodomite_trigger = yes
						}
						rite = { rite_has_doctrine = doctrine_homosexuality_crime }
					}
				}
				scope:doctrine_deviancy_virtuous = {
					scope:recipient = { is_deviant_trigger = yes }
				}
				scope:doctrine_deviancy_accepted = {
					scope:recipient = {
						is_deviant_trigger = yes
						NOT = { rite = { rite_has_doctrine = doctrine_deviancy_virtuous } }
					}
				}
				scope:doctrine_deviancy_shunned = {
					scope:recipient = {
						is_deviant_trigger = yes
						rite = { rite_has_doctrine = doctrine_deviancy_crime }
					}
				}
				scope:doctrine_adultery_men_shunned = {
					scope:recipient = {
						is_female = no
						is_adulterer_or_fornicator_trigger = yes
						NOT = { rite = { rite_has_doctrine = doctrine_adultery_men_accepted } }
					}
				}
				scope:doctrine_adultery_men_accepted = {
					scope:recipient = {
						is_female = no
						is_adulterer_or_fornicator_trigger = yes
					}
				}
				scope:doctrine_adultery_women_shunned = {
					scope:recipient = {
						is_female = yes
						is_adulterer_or_fornicator_trigger = yes
						NOT = { rite = { rite_has_doctrine = doctrine_adultery_women_accepted } }
					}
				}
				scope:doctrine_adultery_women_accepted = {
					scope:recipient = {
						is_female = yes
						is_adulterer_or_fornicator_trigger = yes
					}
				}
				scope:doctrine_witchcraft_virtuous = {
					scope:recipient = { is_witch_trigger = yes }
				}
				scope:doctrine_witchcraft_accepted = {
					scope:recipient = {
						is_witch_trigger = yes
						NOT = { rite = { rite_has_doctrine = doctrine_witchcraft_virtuous } }
					}
				}
				scope:doctrine_witchcraft_shunned = {
					scope:recipient = {
						is_witch_trigger = yes
						rite = { rite_has_doctrine = doctrine_witchcraft_crime }
					}
				}

				scope:doctrine_kinslaying_shunned = {
					scope:recipient = { pam_reaffirm_doctrine_kinslayer_accept_trigger = yes }
				}
				scope:doctrine_kinslaying_accepted = {
					scope:recipient = { pam_reaffirm_doctrine_kinslayer_accept_trigger = yes }
				}

				scope:doctrine_gender_male_dominated = {
					scope:recipient = { is_female = no }
				}
				scope:doctrine_gender_female_dominated = {
					scope:recipient = { is_female = yes }
				}

				scope:doctrine_consanguinity_dynastic = {
					scope:recipient = {
						pam_reaffirm_doctrine_consanguinity_decline_trigger = no
						pam_reaffirm_doctrine_consanguinity_accept_trigger = yes
					}
				}
				scope:doctrine_consanguinity_restricted = {
					scope:recipient = {
						pam_reaffirm_doctrine_consanguinity_decline_trigger = no
						pam_reaffirm_doctrine_consanguinity_accept_trigger = yes
					}
				}
				scope:doctrine_consanguinity_cousins = {
					scope:recipient = {
						pam_reaffirm_doctrine_consanguinity_decline_trigger = no
						pam_reaffirm_doctrine_consanguinity_accept_trigger = yes
					}
				}
				scope:doctrine_consanguinity_aunt_nephew_and_uncle_niece = {
					scope:recipient = {
						pam_reaffirm_doctrine_consanguinity_decline_trigger = no
						pam_reaffirm_doctrine_consanguinity_accept_trigger = yes
					}
				}
				scope:doctrine_consanguinity_unrestricted = {
					scope:recipient = {
						pam_reaffirm_doctrine_consanguinity_decline_trigger = no
						pam_reaffirm_doctrine_consanguinity_accept_trigger = yes
					}
				}

				scope:doctrine_clerical_gender_male_only = {
					scope:recipient = { is_female = no }
				}
				scope:doctrine_clerical_gender_female_only = {
					scope:recipient = { is_female = yes }
				}
				scope:doctrine_clerical_marriage_allowed = {
					scope:recipient = { any_relation = { type = lover } }
				}
				fallback = { always = no }
			}
			desc = pam_reaffirm_doctrine_recipient_desire_reason
		}
	}

	is_shown = {
		scope:recipient = {
			is_adult = yes
			faith ?= scope:actor.faith
			rite != scope:actor.rite
			rite.head_of_rite ?= this
		}
		any_doctrine = {
			scope:actor.rite ?= {
				rite_has_doctrine = prev
			}
			scope:recipient.rite ?= {
				NOT = { rite_has_doctrine = prev }
			}
			pam_doctrine_can_be_reaffirm = yes
		}
	}

	cooldown_against_recipient = { years = 5 }

	cost = {
		piety = {
			value = medium_piety_value
		}
	}

	can_send = {
		trigger_if = {
			limit = {
				scope:actor = { is_ai = no }
			}
			custom_tooltip = {
				text = pam_reaffirm_doctrine_one_doctrine_tt
				pam_reaffirm_doctrine_send_option_selected_trigger = yes
			}
		}
	}

	on_send = {
		if = {
			limit = { scope:actor = { is_ai = yes } }
			random_list = {
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_monogamy
							}
						}
					}
					doctrine:doctrine_monogamy = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_polygamy
							}
						}
					}
					doctrine:doctrine_polygamy = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_concubines
							}
						}
					}
					doctrine:doctrine_concubines = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_divorce_disallowed
							}
						}
					}
					doctrine:doctrine_divorce_disallowed = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_divorce_approval
							}
						}
					}
					doctrine:doctrine_divorce_approval = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_divorce_allowed
							}
						}
					}
					doctrine:doctrine_divorce_allowed = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_bastardry_none
							}
						}
					}
					doctrine:doctrine_bastardry_none = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_bastardry_legitimization
							}
						}
					}
					doctrine:doctrine_bastardry_legitimization = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_bastardry_all
							}
						}
					}
					doctrine:doctrine_bastardry_all = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_homosexuality_crime
							}
						}
					}
					doctrine:doctrine_homosexuality_crime = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_homosexuality_shunned
							}
						}
					}
					doctrine:doctrine_homosexuality_shunned = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_homosexuality_accepted
							}
						}
					}
					doctrine:doctrine_homosexuality_accepted = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_deviancy_crime
							}
						}
					}
					doctrine:doctrine_deviancy_crime = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_deviancy_shunned
							}
						}
					}
					doctrine:doctrine_deviancy_shunned = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_deviancy_accepted
							}
						}
					}
					doctrine:doctrine_deviancy_accepted = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_deviancy_virtuous
							}
						}
					}
					doctrine:doctrine_deviancy_virtuous = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_adultery_men_crime
							}
						}
					}
					doctrine:doctrine_adultery_men_crime = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_adultery_men_shunned
							}
						}
					}
					doctrine:doctrine_adultery_men_shunned = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_adultery_men_accepted
							}
						}
					}
					doctrine:doctrine_adultery_men_accepted = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_adultery_women_crime
							}
						}
					}
					doctrine:doctrine_adultery_women_crime = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_adultery_women_shunned
							}
						}
					}
					doctrine:doctrine_adultery_women_shunned = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_adultery_women_accepted
							}
						}
					}
					doctrine:doctrine_adultery_women_accepted = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_kinslaying_any_dynasty_member_crime
							}
						}
					}
					doctrine:doctrine_kinslaying_any_dynasty_member_crime = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_kinslaying_extended_family_crime
							}
						}
					}
					doctrine:doctrine_kinslaying_extended_family_crime = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_kinslaying_close_kin_crime
							}
						}
					}
					doctrine:doctrine_kinslaying_close_kin_crime = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_kinslaying_shunned
							}
						}
					}
					doctrine:doctrine_kinslaying_shunned = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_kinslaying_accepted
							}
						}
					}
					doctrine:doctrine_kinslaying_accepted = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_witchcraft_crime
							}
						}
					}
					doctrine:doctrine_witchcraft_crime = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_witchcraft_shunned
							}
						}
					}
					doctrine:doctrine_witchcraft_shunned = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_witchcraft_accepted
							}
						}
					}
					doctrine:doctrine_witchcraft_accepted = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_witchcraft_virtuous
							}
						}
					}
					doctrine:doctrine_witchcraft_virtuous = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_gender_male_dominated
							}
						}
					}
					doctrine:doctrine_gender_male_dominated = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_gender_equal
							}
						}
					}
					doctrine:doctrine_gender_equal = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_gender_female_dominated
							}
						}
					}
					doctrine:doctrine_gender_female_dominated = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_consanguinity_dynastic
							}
						}
					}
					doctrine:doctrine_consanguinity_dynastic = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_consanguinity_restricted
							}
						}
					}
					doctrine:doctrine_consanguinity_restricted = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_consanguinity_cousins
							}
						}
					}
					doctrine:doctrine_consanguinity_cousins = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_consanguinity_aunt_nephew_and_uncle_niece
							}
						}
					}
					doctrine:doctrine_consanguinity_aunt_nephew_and_uncle_niece = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_consanguinity_unrestricted
							}
						}
					}
					doctrine:doctrine_consanguinity_unrestricted = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_pluralism_fundamentalist
							}
						}
					}
					doctrine:doctrine_pluralism_fundamentalist = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_pluralism_righteous
							}
						}
					}
					doctrine:doctrine_pluralism_righteous = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_pluralism_pluralistic
							}
						}
					}
					doctrine:doctrine_pluralism_pluralistic = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_theocracy_temporal
							}
						}
					}
					doctrine:doctrine_theocracy_temporal = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_theocracy_lay_clergy
							}
						}
					}
					doctrine:doctrine_theocracy_lay_clergy = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_no_head
							}
						}
					}
					doctrine:doctrine_no_head = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_spiritual_head
							}
						}
					}
					doctrine:doctrine_spiritual_head = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_temporal_head
							}
						}
					}
					doctrine:doctrine_temporal_head = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_clerical_function_taxation
							}
						}
					}
					doctrine:doctrine_clerical_function_taxation = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_clerical_function_alms_and_pacification
							}
						}
					}
					doctrine:doctrine_clerical_function_alms_and_pacification = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_clerical_function_recruitment
							}
						}
					}
					doctrine:doctrine_clerical_function_recruitment = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_clerical_gender_male_only
							}
						}
					}
					doctrine:doctrine_clerical_gender_male_only = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_clerical_gender_either
							}
						}
					}
					doctrine:doctrine_clerical_gender_either = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_clerical_gender_female_only
							}
						}
					}
					doctrine:doctrine_clerical_gender_female_only = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_clerical_marriage_allowed
							}
						}
					}
					doctrine:doctrine_clerical_marriage_allowed = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_clerical_marriage_disallowed
							}
						}
					}
					doctrine:doctrine_clerical_marriage_disallowed = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_clerical_succession_temporal_appointment
							}
						}
					}
					doctrine:doctrine_clerical_succession_temporal_appointment = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_clerical_succession_spiritual_appointment
							}
						}
					}
					doctrine:doctrine_clerical_succession_spiritual_appointment = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_clerical_succession_temporal_fixed_appointment
							}
						}
					}
					doctrine:doctrine_clerical_succession_temporal_fixed_appointment = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_clerical_succession_spiritual_fixed_appointment
							}
						}
					}
					doctrine:doctrine_clerical_succession_spiritual_fixed_appointment = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_clerical_succession_conditional
							}
						}
					}
					doctrine:doctrine_clerical_succession_conditional = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_pilgrimage_forbidden
							}
						}
					}
					doctrine:doctrine_pilgrimage_forbidden = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_pilgrimage_encouraged
							}
						}
					}
					doctrine:doctrine_pilgrimage_encouraged = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_pilgrimage_local_rites
							}
						}
					}
					doctrine:doctrine_pilgrimage_local_rites = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_pilgrimage_mandatory
							}
						}
					}
					doctrine:doctrine_pilgrimage_mandatory = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_pilgrimage_mandatory_hajj
							}
						}
					}
					doctrine:doctrine_pilgrimage_mandatory_hajj = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_funeral_stoic
							}
						}
					}
					doctrine:doctrine_funeral_stoic = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_funeral_bewailment
							}
						}
					}
					doctrine:doctrine_funeral_bewailment = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_funeral_cremation
							}
						}
					}
					doctrine:doctrine_funeral_cremation = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_funeral_sky_burial
							}
						}
					}
					doctrine:doctrine_funeral_sky_burial = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_funeral_mummification
							}
						}
					}
					doctrine:doctrine_funeral_mummification = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_family_rites
							}
						}
					}
					doctrine:doctrine_family_rites = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_no_anointment
							}
						}
					}
					doctrine:doctrine_no_anointment = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_anointment_permitted
							}
						}
					}
					doctrine:doctrine_anointment_permitted = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_imperial_anointment
							}
						}
					}
					doctrine:doctrine_imperial_anointment = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_monotheist
							}
						}
					}
					doctrine:doctrine_monotheist = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_polytheist
							}
						}
					}
					doctrine:doctrine_polytheist = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_monasticism_encouraged
							}
						}
					}
					doctrine:doctrine_monasticism_encouraged = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_monasticism_accepted
							}
						}
					}
					doctrine:doctrine_monasticism_accepted = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_monasticism_absent
							}
						}
					}
					doctrine:doctrine_monasticism_absent = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_monasticism_forbidden
							}
						}
					}
					doctrine:doctrine_monasticism_forbidden = { save_scope_as = pam_reaffirm_doctrine }
				}

				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_sacraments_central
							}
						}
					}
					doctrine:doctrine_sacraments_central = { save_scope_as = pam_reaffirm_doctrine }
				}
				1 = {
					trigger = {
						scope:actor.rite = {
							has_different_doctrine_with_rite_trigger = {
								RITE = scope:recipient.rite
								DOCTRINE = doctrine_sacraments_absent
							}
						}
					}
					doctrine:doctrine_sacraments_absent = { save_scope_as = pam_reaffirm_doctrine }
				}
			}
		}
		else = {
			# Set the tenet based on selected send_options
			switch = {
				trigger = yes
				scope:doctrine_monogamy = { doctrine:doctrine_monogamy = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_polygamy = { doctrine:doctrine_polygamy = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_concubines = { doctrine:doctrine_concubines = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_divorce_disallowed = { doctrine:doctrine_divorce_disallowed = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_divorce_approval = { doctrine:doctrine_divorce_approval = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_divorce_allowed = { doctrine:doctrine_divorce_allowed = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_bastardry_none = { doctrine:doctrine_bastardry_none = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_bastardry_legitimization = { doctrine:doctrine_bastardry_legitimization = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_bastardry_all = { doctrine:doctrine_bastardry_all = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_homosexuality_crime = { doctrine:doctrine_homosexuality_crime = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_homosexuality_shunned = { doctrine:doctrine_homosexuality_shunned = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_homosexuality_accepted = { doctrine:doctrine_homosexuality_accepted = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_deviancy_crime = { doctrine:doctrine_deviancy_crime = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_deviancy_shunned = { doctrine:doctrine_deviancy_shunned = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_deviancy_accepted = { doctrine:doctrine_deviancy_accepted = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_deviancy_virtuous = { doctrine:doctrine_deviancy_virtuous = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_adultery_men_crime = { doctrine:doctrine_adultery_men_crime = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_adultery_men_shunned = { doctrine:doctrine_adultery_men_shunned = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_adultery_men_accepted = { doctrine:doctrine_adultery_men_accepted = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_adultery_women_crime = { doctrine:doctrine_adultery_women_crime = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_adultery_women_shunned = { doctrine:doctrine_adultery_women_shunned = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_adultery_women_accepted = { doctrine:doctrine_adultery_women_accepted = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_kinslaying_any_dynasty_member_crime = { doctrine:doctrine_kinslaying_any_dynasty_member_crime = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_kinslaying_extended_family_crime = { doctrine:doctrine_kinslaying_extended_family_crime = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_kinslaying_close_kin_crime = { doctrine:doctrine_kinslaying_close_kin_crime = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_kinslaying_shunned = { doctrine:doctrine_kinslaying_shunned = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_kinslaying_accepted = { doctrine:doctrine_kinslaying_accepted = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_witchcraft_crime = { doctrine:doctrine_witchcraft_crime = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_witchcraft_shunned = { doctrine:doctrine_witchcraft_shunned = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_witchcraft_accepted = { doctrine:doctrine_witchcraft_accepted = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_witchcraft_virtuous = { doctrine:doctrine_witchcraft_virtuous = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_gender_male_dominated = { doctrine:doctrine_gender_male_dominated = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_gender_equal = { doctrine:doctrine_gender_equal = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_gender_female_dominated = { doctrine:doctrine_gender_female_dominated = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_consanguinity_dynastic = { doctrine:doctrine_consanguinity_dynastic = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_consanguinity_restricted = { doctrine:doctrine_consanguinity_restricted = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_consanguinity_cousins = { doctrine:doctrine_consanguinity_cousins = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_consanguinity_aunt_nephew_and_uncle_niece = { doctrine:doctrine_consanguinity_aunt_nephew_and_uncle_niece = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_consanguinity_unrestricted = { doctrine:doctrine_consanguinity_unrestricted = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_pluralism_fundamentalist = { doctrine:doctrine_pluralism_fundamentalist = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_pluralism_righteous = { doctrine:doctrine_pluralism_righteous = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_pluralism_pluralistic = { doctrine:doctrine_pluralism_pluralistic = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_theocracy_temporal = { doctrine:doctrine_theocracy_temporal = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_theocracy_lay_clergy = { doctrine:doctrine_theocracy_lay_clergy = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_no_head = { doctrine:doctrine_no_head = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_spiritual_head = { doctrine:doctrine_spiritual_head = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_temporal_head = { doctrine:doctrine_temporal_head = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_clerical_function_taxation = { doctrine:doctrine_clerical_function_taxation = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_clerical_function_alms_and_pacification = { doctrine:doctrine_clerical_function_alms_and_pacification = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_clerical_function_recruitment = { doctrine:doctrine_clerical_function_recruitment = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_clerical_gender_male_only = { doctrine:doctrine_clerical_gender_male_only = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_clerical_gender_either = { doctrine:doctrine_clerical_gender_either = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_clerical_gender_female_only = { doctrine:doctrine_clerical_gender_female_only = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_clerical_marriage_allowed = { doctrine:doctrine_clerical_marriage_allowed = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_clerical_marriage_disallowed = { doctrine:doctrine_clerical_marriage_disallowed = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_clerical_succession_temporal_appointment = { doctrine:doctrine_clerical_succession_temporal_appointment = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_clerical_succession_spiritual_appointment = { doctrine:doctrine_clerical_succession_spiritual_appointment = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_clerical_succession_temporal_fixed_appointment = { doctrine:doctrine_clerical_succession_temporal_fixed_appointment = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_clerical_succession_spiritual_fixed_appointment = { doctrine:doctrine_clerical_succession_spiritual_fixed_appointment = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_clerical_succession_conditional = { doctrine:doctrine_clerical_succession_conditional = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_pilgrimage_forbidden = { doctrine:doctrine_pilgrimage_forbidden = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_pilgrimage_encouraged = { doctrine:doctrine_pilgrimage_encouraged = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_pilgrimage_local_rites = { doctrine:doctrine_pilgrimage_local_rites = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_pilgrimage_mandatory = { doctrine:doctrine_pilgrimage_mandatory = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_pilgrimage_mandatory_hajj = { doctrine:doctrine_pilgrimage_mandatory_hajj = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_funeral_stoic = { doctrine:doctrine_funeral_stoic = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_funeral_bewailment = { doctrine:doctrine_funeral_bewailment = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_funeral_cremation = { doctrine:doctrine_funeral_cremation = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_funeral_sky_burial = { doctrine:doctrine_funeral_sky_burial = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_funeral_mummification = { doctrine:doctrine_funeral_mummification = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_family_rites = { doctrine:doctrine_family_rites = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_no_anointment = { doctrine:doctrine_no_anointment = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_anointment_permitted = { doctrine:doctrine_anointment_permitted = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_imperial_anointment = { doctrine:doctrine_imperial_anointment = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_monotheist = { doctrine:doctrine_monotheist = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_polytheist = { doctrine:doctrine_polytheist = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_monasticism_encouraged = { doctrine:doctrine_monasticism_encouraged = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_monasticism_accepted = { doctrine:doctrine_monasticism_accepted = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_monasticism_absent = { doctrine:doctrine_monasticism_absent = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_monasticism_forbidden = { doctrine:doctrine_monasticism_forbidden = { save_scope_as = pam_reaffirm_doctrine } }

				scope:doctrine_sacraments_central = { doctrine:doctrine_sacraments_central = { save_scope_as = pam_reaffirm_doctrine } }
				scope:doctrine_sacraments_absent = { doctrine:doctrine_sacraments_absent = { save_scope_as = pam_reaffirm_doctrine } }
			}
		}
	}

	on_accept = {
		# Needed for character interaction interface to show a proper tooltip when send options are not selected
		if = {
			limit = {
				NOT = { exists = scope:pam_reaffirm_doctrine }
			}
			scope:recipient = {
				custom_tooltip = pam_reaffirm_doctrine_interaction_tooltip
			}
		}
		else = {
			scope:actor = {
				send_interface_toast = {
					type = event_toast_effect_good
					title = pam_reaffirm_doctrine_interaction_toast
					left_icon = scope:actor
					right_icon = scope:recipient

					scope:recipient = {
						rite = {
							change_rite_doctrine = scope:pam_reaffirm_doctrine
						}
					}
					if = {
						limit = {
							scope:hook = yes
							has_usable_hook = scope:recipient
						}
						use_hook = scope:recipient
					}
					scope:actor = {
						add_opinion = {
							target = scope:recipient
							modifier = pleased_opinion
							opinion = 30
						}
					}
					change_spiritual_fulfillment = miniscule_spiritual_fulfillment_value
				}
			}
		}
	}
	
	on_decline = {
		if = {
			limit = {
				NOT = { exists = scope:pam_reaffirm_doctrine }
			}
			scope:actor = {
				change_spiritual_fulfillment = miniscule_spiritual_fulfillment_loss
			}
		}
		else = {
			scope:actor = {
				send_interface_toast = {
					type = event_toast_effect_bad
					title = pam_reaffirm_doctrine_interaction_toast_declined
					left_icon = scope:actor
					right_icon = scope:recipient

					add_opinion = {
						modifier = refusal_opinion
						target = scope:recipient
						opinion = -15
					}
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = subordinates
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 300
		kingdom = 300
		empire = 300
		hegemony = 300
	}

	ai_will_do = {
		base = 25
		modifier = {
			scope:hook = yes
			add = 50
		}
		modifier = {
			add = 50
			scope:actor = {
				has_trait = zealous
			}
		}
		modifier = {
			add = -50
			scope:actor = {
				has_trait = cynical
			}
		}
		modifier = { # More likely to happen during Instability
			add = 15
			scope:actor.religion = religion:christianity_religion
			situation:the_christian_church ?= {
				has_situation_top_phase_parameter = the_christian_church_easier_sway_to_rite
			}
		}
		modifier = { # More likely if the government is religious
			add = 50
			scope:actor = {
				government_is_religious_trigger = yes
			}
		}
		modifier = { # Heresiarchs are able to spread their rites easily
			add = 1000
			scope:actor = {
				OR = {
					has_trait = heresiarch
					has_trait = herald
				}
			}
		}
		modifier = { # target rite has high divergence
			add = "scope:actor.rite.divergence(scope:recipient.rite)"
		}
		modifier = { # Not worth leaning on rites that have barely drifted from ours
			factor = 0
			"scope:actor.rite.divergence(scope:recipient.rite)" < massive_rite_divergence_value
		}
	}

	# doctrine options start
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_monogamy
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_monogamy }
			}
			flag = doctrine_monogamy
			localization = doctrine_monogamy_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_polygamy
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_polygamy }
			}
			flag = doctrine_polygamy
			localization = doctrine_polygamy_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_concubines
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_concubines }
			}
			flag = doctrine_concubines
			localization = doctrine_concubines_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_divorce_disallowed
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_divorce_disallowed }
			}
			flag = doctrine_divorce_disallowed
			localization = doctrine_divorce_disallowed_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_divorce_approval
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_divorce_approval }
			}
			flag = doctrine_divorce_approval
			localization = doctrine_divorce_approval_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_divorce_allowed
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_divorce_allowed }
			}
			flag = doctrine_divorce_allowed
			localization = doctrine_divorce_allowed_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_bastardry_none
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_bastardry_none }
			}
			flag = doctrine_bastardry_none
			localization = doctrine_bastardry_none_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_bastardry_legitimization
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_bastardry_legitimization }
			}
			flag = doctrine_bastardry_legitimization
			localization = doctrine_bastardry_legitimization_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_bastardry_all
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_bastardry_all }
			}
			flag = doctrine_bastardry_all
			localization = doctrine_bastardry_all_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_homosexuality_crime
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_homosexuality_crime }
			}
			flag = doctrine_homosexuality_crime
			localization = doctrine_homosexuality_crime_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_homosexuality_shunned
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_homosexuality_shunned }
			}
			flag = doctrine_homosexuality_shunned
			localization = doctrine_homosexuality_shunned_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_homosexuality_accepted
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_homosexuality_accepted }
			}
			flag = doctrine_homosexuality_accepted
			localization = doctrine_homosexuality_accepted_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_deviancy_crime
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_deviancy_crime }
			}
			flag = doctrine_deviancy_crime
			localization = doctrine_deviancy_crime_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_deviancy_shunned
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_deviancy_shunned }
			}
			flag = doctrine_deviancy_shunned
			localization = doctrine_deviancy_shunned_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_deviancy_accepted
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_deviancy_accepted }
			}
			flag = doctrine_deviancy_accepted
			localization = doctrine_deviancy_accepted_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_deviancy_virtuous
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_deviancy_virtuous }
			}
			flag = doctrine_deviancy_virtuous
			localization = doctrine_deviancy_virtuous_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_adultery_men_crime
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_adultery_men_crime }
			}
			flag = doctrine_adultery_men_crime
			localization = doctrine_adultery_men_crime_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_adultery_men_shunned
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_adultery_men_shunned }
			}
			flag = doctrine_adultery_men_shunned
			localization = doctrine_adultery_men_shunned_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_adultery_men_accepted
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_adultery_men_accepted }
			}
			flag = doctrine_adultery_men_accepted
			localization = doctrine_adultery_men_accepted_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_adultery_women_crime
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_adultery_women_crime }
			}
			flag = doctrine_adultery_women_crime
			localization = doctrine_adultery_women_crime_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_adultery_women_shunned
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_adultery_women_shunned }
			}
			flag = doctrine_adultery_women_shunned
			localization = doctrine_adultery_women_shunned_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_adultery_women_accepted
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_adultery_women_accepted }
			}
			flag = doctrine_adultery_women_accepted
			localization = doctrine_adultery_women_accepted_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_kinslaying_any_dynasty_member_crime
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_kinslaying_any_dynasty_member_crime }
			}
			flag = doctrine_kinslaying_any_dynasty_member_crime
			localization = doctrine_kinslaying_any_dynasty_member_crime_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_kinslaying_extended_family_crime
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_kinslaying_extended_family_crime }
			}
			flag = doctrine_kinslaying_extended_family_crime
			localization = doctrine_kinslaying_extended_family_crime_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_kinslaying_close_kin_crime
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_kinslaying_close_kin_crime }
			}
			flag = doctrine_kinslaying_close_kin_crime
			localization = doctrine_kinslaying_close_kin_crime_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_kinslaying_shunned
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_kinslaying_shunned }
			}
			flag = doctrine_kinslaying_shunned
			localization = doctrine_kinslaying_shunned_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_kinslaying_accepted
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_kinslaying_accepted }
			}
			flag = doctrine_kinslaying_accepted
			localization = doctrine_kinslaying_accepted_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_witchcraft_crime
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_witchcraft_crime }
			}
			flag = doctrine_witchcraft_crime
			localization = doctrine_witchcraft_crime_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_witchcraft_shunned
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_witchcraft_shunned }
			}
			flag = doctrine_witchcraft_shunned
			localization = doctrine_witchcraft_shunned_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_witchcraft_accepted
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_witchcraft_accepted }
			}
			flag = doctrine_witchcraft_accepted
			localization = doctrine_witchcraft_accepted_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_witchcraft_virtuous
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_witchcraft_virtuous }
			}
			flag = doctrine_witchcraft_virtuous
			localization = doctrine_witchcraft_virtuous_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_gender_male_dominated
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_gender_male_dominated }
			}
			flag = doctrine_gender_male_dominated
			localization = doctrine_gender_male_dominated_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_gender_equal
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_gender_equal }
			}
			flag = doctrine_gender_equal
			localization = doctrine_gender_equal_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_gender_female_dominated
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_gender_female_dominated }
			}
			flag = doctrine_gender_female_dominated
			localization = doctrine_gender_female_dominated_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_consanguinity_dynastic
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_consanguinity_dynastic }
			}
			flag = doctrine_consanguinity_dynastic
			localization = doctrine_consanguinity_dynastic_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_consanguinity_restricted
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_consanguinity_restricted }
			}
			flag = doctrine_consanguinity_restricted
			localization = doctrine_consanguinity_restricted_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_consanguinity_cousins
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_consanguinity_cousins }
			}
			flag = doctrine_consanguinity_cousins
			localization = doctrine_consanguinity_cousins_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_consanguinity_aunt_nephew_and_uncle_niece
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_consanguinity_aunt_nephew_and_uncle_niece }
			}
			flag = doctrine_consanguinity_aunt_nephew_and_uncle_niece
			localization = doctrine_consanguinity_aunt_nephew_and_uncle_niece_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_consanguinity_unrestricted
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_consanguinity_unrestricted }
			}
			flag = doctrine_consanguinity_unrestricted
			localization = doctrine_consanguinity_unrestricted_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_pluralism_fundamentalist
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_pluralism_fundamentalist }
			}
			flag = doctrine_pluralism_fundamentalist
			localization = doctrine_pluralism_fundamentalist_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_pluralism_righteous
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_pluralism_righteous }
			}
			flag = doctrine_pluralism_righteous
			localization = doctrine_pluralism_righteous_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_pluralism_pluralistic
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_pluralism_pluralistic }
			}
			flag = doctrine_pluralism_pluralistic
			localization = doctrine_pluralism_pluralistic_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_theocracy_temporal
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_theocracy_temporal }
			}
			flag = doctrine_theocracy_temporal
			localization = doctrine_theocracy_temporal_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_theocracy_lay_clergy
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_theocracy_lay_clergy }
			}
			flag = doctrine_theocracy_lay_clergy
			localization = doctrine_theocracy_lay_clergy_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_no_head
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_no_head }
			}
			flag = doctrine_no_head
			localization = doctrine_no_head_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_spiritual_head
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_spiritual_head }
			}
			flag = doctrine_spiritual_head
			localization = doctrine_spiritual_head_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_temporal_head
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_temporal_head }
			}
			flag = doctrine_temporal_head
			localization = doctrine_temporal_head_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_clerical_function_taxation
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_clerical_function_taxation }
			}
			flag = doctrine_clerical_function_taxation
			localization = doctrine_clerical_function_taxation_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_clerical_function_alms_and_pacification
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_clerical_function_alms_and_pacification }
			}
			flag = doctrine_clerical_function_alms_and_pacification
			localization = doctrine_clerical_function_alms_and_pacification_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_clerical_function_recruitment
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_clerical_function_recruitment }
			}
			flag = doctrine_clerical_function_recruitment
			localization = doctrine_clerical_function_recruitment_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_clerical_gender_male_only
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_clerical_gender_male_only }
			}
			flag = doctrine_clerical_gender_male_only
			localization = doctrine_clerical_gender_male_only_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_clerical_gender_either
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_clerical_gender_either }
			}
			flag = doctrine_clerical_gender_either
			localization = doctrine_clerical_gender_either_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_clerical_gender_female_only
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_clerical_gender_female_only }
			}
			flag = doctrine_clerical_gender_female_only
			localization = doctrine_clerical_gender_female_only_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_clerical_marriage_allowed
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_clerical_marriage_allowed }
			}
			flag = doctrine_clerical_marriage_allowed
			localization = doctrine_clerical_marriage_allowed_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_clerical_marriage_disallowed
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_clerical_marriage_disallowed }
			}
			flag = doctrine_clerical_marriage_disallowed
			localization = doctrine_clerical_marriage_disallowed_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_clerical_succession_temporal_appointment
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_clerical_succession_temporal_appointment }
			}
			flag = doctrine_clerical_succession_temporal_appointment
			localization = doctrine_clerical_succession_temporal_appointment_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_clerical_succession_spiritual_appointment
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_clerical_succession_spiritual_appointment }
			}
			flag = doctrine_clerical_succession_spiritual_appointment
			localization = doctrine_clerical_succession_spiritual_appointment_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_clerical_succession_temporal_fixed_appointment
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_clerical_succession_temporal_fixed_appointment }
			}
			flag = doctrine_clerical_succession_temporal_fixed_appointment
			localization = doctrine_clerical_succession_temporal_fixed_appointment_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_clerical_succession_spiritual_fixed_appointment
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_clerical_succession_spiritual_fixed_appointment }
			}
			flag = doctrine_clerical_succession_spiritual_fixed_appointment
			localization = doctrine_clerical_succession_spiritual_fixed_appointment_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_clerical_succession_conditional
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_clerical_succession_conditional }
			}
			flag = doctrine_clerical_succession_conditional
			localization = doctrine_clerical_succession_conditional_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_pilgrimage_forbidden
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_pilgrimage_forbidden }
			}
			flag = doctrine_pilgrimage_forbidden
			localization = doctrine_pilgrimage_forbidden_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_pilgrimage_encouraged
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_pilgrimage_encouraged }
			}
			flag = doctrine_pilgrimage_encouraged
			localization = doctrine_pilgrimage_encouraged_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_pilgrimage_local_rites
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_pilgrimage_local_rites }
			}
			flag = doctrine_pilgrimage_local_rites
			localization = doctrine_pilgrimage_local_rites_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_pilgrimage_mandatory
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_pilgrimage_mandatory }
			}
			flag = doctrine_pilgrimage_mandatory
			localization = doctrine_pilgrimage_mandatory_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_pilgrimage_mandatory_hajj
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_pilgrimage_mandatory_hajj }
			}
			flag = doctrine_pilgrimage_mandatory_hajj
			localization = doctrine_pilgrimage_mandatory_hajj_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_funeral_stoic
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_funeral_stoic }
			}
			flag = doctrine_funeral_stoic
			localization = doctrine_funeral_stoic_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_funeral_bewailment
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_funeral_bewailment }
			}
			flag = doctrine_funeral_bewailment
			localization = doctrine_funeral_bewailment_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_funeral_cremation
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_funeral_cremation }
			}
			flag = doctrine_funeral_cremation
			localization = doctrine_funeral_cremation_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_funeral_sky_burial
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_funeral_sky_burial }
			}
			flag = doctrine_funeral_sky_burial
			localization = doctrine_funeral_sky_burial_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_funeral_mummification
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_funeral_mummification }
			}
			flag = doctrine_funeral_mummification
			localization = doctrine_funeral_mummification_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_family_rites
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_family_rites }
			}
			flag = doctrine_family_rites
			localization = doctrine_family_rites_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_no_anointment
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_no_anointment }
			}
			flag = doctrine_no_anointment
			localization = doctrine_no_anointment_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_anointment_permitted
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_anointment_permitted }
			}
			flag = doctrine_anointment_permitted
			localization = doctrine_anointment_permitted_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_imperial_anointment
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_imperial_anointment }
			}
			flag = doctrine_imperial_anointment
			localization = doctrine_imperial_anointment_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_monotheist
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_monotheist }
			}
			flag = doctrine_monotheist
			localization = doctrine_monotheist_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_polytheist
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_polytheist }
			}
			flag = doctrine_polytheist
			localization = doctrine_polytheist_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_monasticism_encouraged
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_monasticism_encouraged }
			}
			flag = doctrine_monasticism_encouraged
			localization = doctrine_monasticism_encouraged_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_monasticism_accepted
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_monasticism_accepted }
			}
			flag = doctrine_monasticism_accepted
			localization = doctrine_monasticism_accepted_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_monasticism_absent
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_monasticism_absent }
			}
			flag = doctrine_monasticism_absent
			localization = doctrine_monasticism_absent_descriptive_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_monasticism_forbidden
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_monasticism_forbidden }
			}
			flag = doctrine_monasticism_forbidden
			localization = doctrine_monasticism_forbidden_descriptive_name
		}

		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_sacraments_central
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_sacraments_central }
			}
			flag = doctrine_sacraments_central
			localization = doctrine_sacraments_central_name
		}
		send_option = {
			is_shown = {
				scope:actor.rite = {
					has_different_doctrine_with_rite_trigger = {
						RITE = scope:recipient.rite
						DOCTRINE = doctrine_sacraments_absent
					}
				}
			}
			is_valid = {
				pam_reaffirm_doctrine_send_option_valid_trigger = { DOCTRINE = doctrine_sacraments_absent }
			}
			flag = doctrine_sacraments_absent
			localization = doctrine_sacraments_absent_name
		}
	# doctrine options end
}

# Force someone to step down
request_enforce_succession_interaction = {
	category = interaction_category_religion
	icon = icon_clergy_succession
	interface_priority = 38
	common_interaction = no
	notification_text = request_enforce_succession_interaction_notification
	greeting = positive

	target_type = title
	target_filter = claimed_titles
	target_source = actor

	use_diplomatic_range = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes

	desc = request_enforce_succession_interaction_desc

	cooldown_against_recipient = { years = 5 }

	is_available = {
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			religion ?= religion:christianity_religion
			any_claim = { } # You have a claim to force succession for
			NOT = {
				government_has_flag = government_is_theocracy
			}
			pam_clergy_interactions_faith_trigger = yes
			is_ruler = yes
		}
		scope:puppet_or_actor ?= {
			NOT = {
				is_at_war_with = scope:recipient
			}
			capital_county.clerical_region_title.holder ?= scope:recipient
		}
		scope:recipient = {
			pam_request_legitimacy_priest_trigger = { CHARACTER = scope:puppet_or_actor }
			any_held_title = {
				has_clerical_region = yes
			}
		}
		pam_should_bother_clergy_interaction_trigger = { PRIEST = scope:recipient }
	}

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
			}
			age >= 12
			legitimacy_level >= 3
			
			NOR = {
				has_trait = excommunicated
				has_character_modifier = promised_pilgrimage_to_clergy_modifier
			}
			custom_tooltip = { # You cannot request this if you are sponsoring an antipope _unless_ the recipient is the antipope
				text = actor_is_antipope_sponsor_tt
				scope:actor = { pam_is_antipope_sponsor_trigger = no }
				scope:recipient = { pam_is_antipope_trigger = no }
			}
		}
		scope:recipient = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
				adult = yes
			}
			NOT = {
				has_trait = excommunicated
			}
			highest_held_title_tier >= tier_duchy
			custom_tooltip = {
				text = request_enforce_succession_must_be_archbishop_tt
				scope:puppet_or_actor.capital_county.clerical_region_title.holder ?= this
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= medium_piety_value
			}
		}
	}

	has_valid_target_showing_failures_only = {
		exists = scope:target
		custom_tooltip = {
			text = request_enforce_succession_no_valid_title_tt
			pam_valid_enforce_succession_title_trigger = {
				TITLE = scope:target
				ACTOR = scope:puppet_or_actor
			}
		}
	}

	can_be_picked_title = {
		pam_valid_enforce_succession_title_trigger = {
			TITLE = scope:target
			ACTOR = scope:puppet_or_actor
		}
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				add_piety = { value = { add = medium_piety_value max = piety multiply = -1 } }
			}
		}
		scope:puppet_or_actor = {
			pam_enforce_title_succession_effect = yes
			trigger_event = pam_interactions_events.0081
			scope:succession_holder = {
				trigger_event = pam_interactions_events.0082
			}
		}
		pam_offer_pilgrimage_effect = {
			ACTOR = scope:puppet_or_actor
			CLERIC = scope:recipient
		}
		scope:recipient = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = request_enforce_succession_recipient_toast
				left_icon = scope:recipient
				right_icon = scope:puppet_or_actor
				if = {
					limit = {
						can_add_hook = {
							target = scope:puppet_or_actor
							type = favor_hook
						}
					}
					add_hook_no_toast = {
						target = scope:puppet_or_actor
						type = favor_hook
					}
				}
			}
		}
	}

	on_decline = {
		if = {
			limit = {
				scope:recipient = {
					is_ai = no
				}
			}
			scope:puppet_or_actor = {
				add_opinion = {
					modifier = refusal_opinion
					target = scope:recipient
					opinion = -15
				}
			}
		}
	}

	send_options_exclusive = no

	send_option = {
		is_shown = {
			pam_actor_rite_has_core_simony_trigger = yes
		}
		is_valid = {
			scope:puppet_or_actor = {
				short_term_gold >= major_gold_value
			}
		}
		flag = donate_faith
		localization = DONATE_TO_THE_FAITH_INTERACTION_OPTION
	}

	send_option = {
		is_shown = {
			pam_offer_pilgrimage_option_shown_trigger = { ACTOR = scope:puppet_or_actor }
		}
		is_valid = {
			pam_offer_pilgrimage_option_valid_trigger = { ACTOR = scope:puppet_or_actor }
		}
		flag = offer_pilgrimage
		localization = OFFER_PILGRIMAGE_INTERACTION_OPTION
	}

	cost = {
		piety = {
			value = medium_piety_value
			multiply = pam_peace_of_god_clergy_peacemaking_cost_mult_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
		gold = {
			value = 0
			if = {
				limit = { scope:donate_faith = yes }
				add = major_gold_value
			}
		}
	}

	ai_accept = {
		base = -30

		modifier = { # By God Alone - Secular Faith: the petitioner holds the ear of the clergy
			add = 25
			desc = pam_sf_ear_of_clergy_accept_reason
			trigger = {
				scope:puppet_or_actor = { has_character_modifier = pam_sf_ear_of_clergy_modifier }
			}
		}

		modifier = { # Peace of God: settling succession is preferable to a war over it
			add = 40
			desc = pam_peace_of_god_clergy_peacemaking_accept_reason
			trigger = {
				scope:recipient.rite ?= {
					rite_has_parameter = tenet_peace_of_god_clergy_peacemaking
				}
			}
		}

		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}

		modifier = {
			exists = scope:target.holder
			scope:target.holder = {
				NOT = {
					is_in_same_clerical_region_as_trigger = { TARGET = scope:actor }
				}
			}
			add = -20
			desc = REQUEST_ENFORCE_SUCCESSION_HOLDER_OUTSIDE_DIOCESE_REASON
		}
		
		modifier = {
			exists = scope:actor.liege
			scope:target.holder ?= scope:actor.liege
			add = -50
			desc = REQUEST_ENFORCE_SUCCESSION_LIEGE_TITLE_REASON
		}
		
		modifier = {
			scope:actor = {
				OR = {
					has_trait = saint
					has_trait = herald
					has_trait = saoshyant_descendant
					has_trait = order_member
					has_trait = faith_warrior
					has_trait = saoshyant
					has_trait = paragon
					has_trait = savior
					has_trait = crusader_king
				}
			}
			add = 100
			desc = VERY_PIOUS_TRAITS_REASON
		}
		
		modifier = {
			scope:actor = {
				OR = {
					has_trait = zealous
					has_trait = theologian
					has_trait = divine_blood
					has_trait = consecrated_blood
					has_trait = sayyid
				}
			}
			add = 30
			desc = PIOUS_TRAITS_REASON
		}
	
		# Fs
		modifier = {
			add = 30
			scope:recipient = {
				has_relation_friend = scope:actor
			}
			desc = WE_ARE_FRIENDS
		}
		# BFFs
		modifier = {
			add = 60
			scope:recipient = {
				has_relation_best_friend = scope:actor
			}
			desc = WE_ARE_BEST_FRIENDS
		}
		# Take dread into account
		modifier = {
			add = {
				value = 25
				if = {
					limit = {
						scope:recipient = {
							target_is_liege_or_above = scope:actor
						}
					}
					multiply = 2
				}
			}
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = {
				value = 50
				if = {
					limit = {
						scope:recipient = {
							target_is_liege_or_above = scope:actor
						}
					}
					multiply = 2
				}
			}
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		
		modifier = {
			add = 100
			scope:actor.puppet:theological_agent_puppet ?= scope:recipient
			desc = IS_YOUR_PUPPET
		}
		
		modifier = {
			scope:actor.num_sinful_traits > 0
			add = {
				value = -10
				multiply = scope:actor.num_sinful_traits
			}
			desc = I_AM_SINFUL
		}

		modifier = {
			exists = scope:target.holder
			scope:target.holder = {
				num_sinful_traits > 0
			}
			add = {
				value = 10
				multiply = scope:target.holder.num_sinful_traits
			}
			desc = REQUEST_ENFORCE_SUCCESSION_HOLDER_SINFUL_REASON
		}

		modifier = {
			exists = scope:target.holder
			add = {
				value = scope:actor.piety_level
				subtract = scope:target.holder.piety_level
				multiply = 15
				min = 0
			}
			scope:actor.piety_level > scope:target.holder.piety_level
			desc = REQUEST_ENFORCE_SUCCESSION_ACTOR_MORE_PIOUS_REASON
		}

		modifier = {
			exists = scope:target.holder
			add = {
				value = scope:target.holder.piety_level
				subtract = scope:actor.piety_level
				multiply = -15
				min = 0
			}
			scope:target.holder.piety_level > scope:actor.piety_level
			desc = REQUEST_ENFORCE_SUCCESSION_HOLDER_MORE_PIOUS_REASON
		}

		modifier = {
			exists = scope:target.holder
			scope:target.holder = {
				NOT = {
					any_child = {
						is_alive = yes
					}
				}
			}
			add = 30
			desc = REQUEST_ENFORCE_SUCCESSION_HOLDER_CHILDLESS_REASON
		}
		modifier = {
			add = {
				value = 25
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:puppet_or_actor.major_gold_value < scope:recipient.minor_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 50
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:puppet_or_actor.major_gold_value < scope:recipient.major_gold_value
			scope:puppet_or_actor.major_gold_value >= scope:recipient.minor_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 75
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:puppet_or_actor.major_gold_value >= scope:recipient.major_gold_value
			scope:puppet_or_actor.major_gold_value < scope:recipient.monumental_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 100
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:puppet_or_actor.major_gold_value >= scope:recipient.monumental_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = pam_offer_pilgrimage_acceptance_value
			scope:offer_pilgrimage = yes
			desc = OFFER_PILGRIMAGE_INTERACTION_OPTION_REASON
		}
		#RITE RELATIONS
		modifier = { # Head of Rite is more convincing
			add = 50
			scope:actor.rite = scope:recipient.rite
			scope:actor.rite.head_of_rite ?= scope:actor
			desc = HEAD_OF_RITE_REASON
		}
		modifier = {
			scope:actor = {
				NOT = { rite = scope:recipient.rite }
			}
			add = -20
			desc = DIFFERENT_RITE_REASON
		}
		modifier = {
			scope:actor = {
				NOT = { rite = scope:recipient.rite }
			}
			scope:recipient = {
				rite_fulfillment_score = {
					target = scope:actor.rite
					value >= 75
				}
			}
			add = 25
			desc = PERSONAL_APPROVAL_OF_RITE_REASON
		}
		modifier = {
			scope:actor = {
				NOT = { rite = scope:recipient.rite }
			}
			scope:recipient = {
				rite_fulfillment_score = {
					target = scope:actor.rite
					value < 25
				}
			}
			add = -25
			desc = PERSONAL_DISAPPROVAL_OF_RITE_REASON
		}
		#Your rite is heretical
		modifier = {
			scope:actor = {
				NOT = { rite = scope:recipient.rite }
			}
			any_tenet = {
				scope:actor.rite = {
					has_tenet_status = {
						tenet = prev
						status = core
					}
				}
				scope:recipient.rite = {
					has_tenet_status = {
						tenet = prev
						status = prohibited
					}
				}
			}
			add = -100
			desc = RITE_CORE_TENET_PROHIBITED
		}
		modifier = {
			scope:actor = {
				NOT = { rite = scope:recipient.rite }
			}
			any_tenet = {
				scope:actor.rite = {
					has_tenet_status = {
						tenet = prev
						status = permitted
					}
				}
				scope:recipient.rite = {
					has_tenet_status = {
						tenet = prev
						status = prohibited
					}
				}
			}
			add = -40
			desc = RITE_TENET_PROHIBITED
		}
	}

	ai_targets = {
		ai_recipients = rulers_in_clerical_region
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 48
		duchy = 36
		kingdom = 24
		empire = 24
		hegemony = 24
	}

	ai_will_do = {
		base = 0

		modifier = {
			exists = scope:target
			scope:actor = {
				has_claim_on = scope:target
			}
			add = 50
		}

		modifier = {
			exists = scope:target.holder
			scope:target.holder = {
				NOT = {
					any_child = {
						is_alive = yes
					}
				}
			}
			add = 25
		}

		modifier = {
			scope:actor = {
				piety_level >= 3
			}
			add = 15
		}

		modifier = {
			scope:actor = {
				num_sinful_traits >= 2
			}
			add = -40
		}
	}
}

# Ecclesiastical rulers petition a religious superior or subordinate for treasury funds
request_ecclesiastical_treasury_interaction = {
	category = interaction_category_religion
	icon = request_ecclesiastical_treasury_interaction
	interface_priority = 45
	common_interaction = yes
	notification_text = request_ecclesiastical_treasury_interaction_notification
	greeting = positive

	use_diplomatic_range = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes

	desc = request_ecclesiastical_treasury_interaction_desc

	cooldown_against_recipient = { years = 5 }
	
	recipient_recieve_cooldown = {
		years = marriage_recieve_proposal_cooldown # Intentional
	}
	
	ignore_recipient_recieve_cooldown = {
		AND = {
			is_ai = no
			scope:recipient = { is_ai = no }
		}
	}

	is_available = {
		government_has_flag = government_is_ecclesiastical
		has_pam_dlc_trigger = yes
		is_adult = yes
	}

	is_shown = {
		scope:actor = {
			pam_ecclesiastical_superior_or_subordinate_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		scope:recipient = {
			faith ?= scope:actor.faith
			government_has_flag = government_is_ecclesiastical
			is_ruler = yes
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
			}
			NOT = {
				has_trait = excommunicated
			}
			NOT = {
				is_at_war_with = scope:recipient
			}
			pam_not_antipope_when_recipient_is_hof_tt = { CHARACTER = scope:actor }
		}
		scope:recipient = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
				adult = yes
			}
			NOT = {
				has_trait = excommunicated
			}
			treasury >= medium_treasury_or_gold_value
		}
	}

	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:actor = {
			has_usable_hook = scope:recipient
		}
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"
	send_options_exclusive = no
	
	cost = {
		piety = {
			value = medium_piety_value
			if = {
				limit = {
					scope:actor = {
						domicile ?= { has_domicile_parameter = estate_cheaper_treasury_request }
					}
				}
				multiply = ecclesiastical_domicile_cheaper_treasury_request_mult
			}
		}
	}

	auto_accept = {
		custom_description = {
			text = spending_hook
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
	}

	on_accept = {
		scope:actor = {
			if = {
				limit = {
					scope:hook = yes
					has_usable_hook = scope:recipient
				}
				use_hook = scope:recipient
			}
			send_interface_toast = {
				type = event_toast_effect_good
				title = request_ecclesiastical_treasury_interaction_title
				right_icon = scope:recipient
				scope:recipient = {
					pay_treasury_or_gold = {
						target = scope:actor
						value = medium_treasury_or_gold_value
					}
					add_piety = minor_piety_value
					if = {
						limit = {
							OR = {
								AND = {
									has_trait = generous
									rite = { trait_is_virtue_rite = generous }
								}
								rite = {
									has_tenet_status = {
										tenet = tenet_philanthropia
										status = core
									}
								}
								has_personal_tenet = tenet_philanthropia
							}
						}
						change_spiritual_fulfillment = minor_spiritual_fulfillment_value
					}
				}
			}
		}
	}

	on_decline = {
		scope:recipient = {
			add_piety = miniscule_piety_loss
		}
		if = {
			limit = {
				scope:recipient = {
					is_ai = no
				}
			}
			scope:actor = {
				add_opinion = {
					modifier = refusal_opinion
					target = scope:recipient
					opinion = -15
				}
			}
		}
	}

	ai_accept = {
		base = -25

		modifier = {
			scope:hook = yes
			add = 200
			desc = SCHEME_WEAK_HOOK_USED
		}

		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}

		modifier = {
			add = 25
			scope:actor = {
				any_sub_realm_county = {
					faith != scope:actor.faith
				}
			}
			desc = REQUEST_ECCLESIASTICAL_TREASURY_NON_FAITH_COUNTIES_REASON
		}

		modifier = {
			add = ecclesiastical_domicile_acceptance_value_1
			desc = ESTATE_TREASURY_REQUEST_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_easier_treasury_request_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_value_2
			desc = ESTATE_TREASURY_REQUEST_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_easier_treasury_request_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_value_3
			desc = ESTATE_TREASURY_REQUEST_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_easier_treasury_request_3
				}
			}
		}
		ecclesiastical_domicile_cathedral_awe_modifier = yes

		modifier = {
			add = 25
			scope:actor = {
				any_character_war = {
					using_holy_war_cb_trigger = yes
				}
			}
			desc = REQUEST_ECCLESIASTICAL_TREASURY_HOLY_WAR_REASON
		}

		modifier = {
			add = 20
			scope:recipient = {
				has_trait = generous
			}
			desc = INTERACTION_GENEROUS
		}

		modifier = {
			add = -25
			scope:recipient = {
				has_trait = greedy
			}
			desc = INTERACTION_GREEDY
		}

		modifier = {
			add = -30
			scope:recipient = {
				treasury <= {
					value = medium_treasury_or_gold_value
				}
			}
			desc = REQUEST_ECCLESIASTICAL_TREASURY_RECIPIENT_LOW_TREASURY_REASON
		}

		modifier = { # AI-to-AI only, and undescribed: a reserve between AI characters must never read
			# to a player as an unexplained refusal, in either direction
			add = -1000
			scope:actor = { is_ai = yes }
			scope:recipient = {
				is_ai = yes
				any_held_title = { is_head_of_faith = yes }
				treasury < pam_head_of_faith_treasury_reserve_value
			}
		}

		modifier = {
			add = -50
			NOR = {
				scope:actor.superior ?= scope:recipient
				scope:recipient.superior ?= scope:actor
			}
			desc = REQUEST_ECCLESIASTICAL_TREASURY_NOT_IMMEDIATE_REASON
		}

		modifier = {
			add = 25
			scope:actor = {
				dynasty ?= { has_dynasty_perk = pam_legacy_2 }
			}
			desc = REQUEST_ECCLESIASTICAL_TREASURY_LEGACY_DYNASTY_REASON
		}

		modifier = { # Undescribed: gated on an AI asker, so this line can never reach a player's tooltip
			add = 40
			scope:actor = {
				is_ai = yes
				any_held_title = { is_head_of_faith = yes }
			}
		}
	}

	ai_targets = {
		ai_recipients = subordinates
	}
	ai_targets = {
		ai_recipients = superior
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 36
		duchy = 24
		kingdom = 6
		empire = 6
		hegemony = 6
	}

	ai_will_do = {
		base = 0
		
		modifier = {
			debt_level >= 0
			add = 100
		}

		modifier = {
			scope:actor.treasury < 0
			add = 40
		}

		modifier = {
			scope:actor.treasury <= minor_treasury_value
			add = 20
		}

		modifier = { # A Head of Faith calling on his own prelates is routine, not a sign of desperation
			add = 40
			scope:actor = {
				any_held_title = { is_head_of_faith = yes }
			}
		}

		modifier = {
			scope:hook = yes
			add = 50
		}

		modifier = {
			scope:actor = {
				any_character_war = {
					using_holy_war_cb_trigger = yes
				}
			}
			add = 30
		}

		modifier = {
			scope:actor.superior.superior ?= scope:recipient
			factor = 0
		}
	}
}

pam_ask_subordinates_for_gold_interaction = {
	category = interaction_category_religion
	icon = icon_gold
	interface_priority = 44
	common_interaction = yes
	notification_text = pam_ask_subordinates_for_gold_interaction_notification
	greeting = positive

	use_diplomatic_range = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes

	desc = pam_ask_subordinates_for_gold_interaction_desc

	cooldown = { years = 1 }
	cooldown_against_recipient = { years = 5 }

	is_available = {
		has_pam_dlc_trigger = yes
		is_adult = yes
	}

	is_shown = {
		scope:actor = {
			pam_is_clerical_comprehensive_trigger = yes
			any_subordinate = { this = scope:recipient }
		}
		scope:recipient = {
			faith ?= scope:actor.faith
			trigger_if = {
				limit = { faith.religious_head ?= scope:actor }
				pam_is_antipope_trigger = no
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
			}
			NOR = {
				has_trait = excommunicated
				is_at_war_with = scope:recipient
			}
		}
		scope:recipient = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				adult = yes
			}
			NOT = {
				has_trait = excommunicated
			}
			treasury_or_gold >= minor_treasury_or_gold_value
		}
	}

	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:actor = {
			has_usable_hook = scope:recipient
		}
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"
	send_options_exclusive = no

	cost = {
		piety = pam_ask_subordinates_for_gold_piety_cost_value
	}

	auto_accept = {
		custom_description = {
			text = spending_hook
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
	}

	on_accept = {
		save_scope_value_as = {
			name = siphoned_amount
			value = scope:recipient.pam_ask_subordinates_for_gold_value
		}
		scope:actor = {
			if = {
				limit = {
					scope:hook = yes
					has_usable_hook = scope:recipient
				}
				use_hook = scope:recipient
			}
			send_interface_toast = {
				type = event_toast_effect_good
				title = pam_ask_subordinates_for_gold_interaction_title
				right_icon = scope:recipient
				add_short_term_gold = scope:siphoned_amount
				scope:recipient = {
					remove_treasury_or_gold = scope:siphoned_amount
					add_piety = minor_piety_value
				}
			}
		}
	}

	on_decline = {
		if = {
			limit = {
				scope:recipient = {
					is_ai = no
				}
			}
			scope:actor = {
				add_opinion = {
					modifier = refusal_opinion
					target = scope:recipient
					opinion = -15
				}
			}
		}
	}

	ai_accept = {
		base = -10

		ask_for_gold_acceptance_modifier = yes

		modifier = {
			scope:hook = yes
			add = 200
			desc = SCHEME_WEAK_HOOK_USED
		}

		modifier = {
			add = 20
			scope:recipient = {
				has_trait = generous
			}
			desc = INTERACTION_GENEROUS
		}

		modifier = {
			add = -25
			scope:recipient = {
				has_trait = greedy
			}
			desc = INTERACTION_GREEDY
		}

		modifier = {
			add = -30
			scope:recipient = {
				treasury_or_gold <= medium_treasury_or_gold_value
			}
			desc = REQUEST_ECCLESIASTICAL_TREASURY_RECIPIENT_LOW_TREASURY_REASON
		}

		modifier = { # Undescribed: gated on an AI asker, so this line can never reach a player's tooltip
			add = 100
			scope:actor = {
				is_ai = yes
				any_held_title = { is_head_of_faith = yes }
			}
		}
	}

	ai_targets = {
		ai_recipients = subordinates
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 36
		duchy = 24
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_will_do = {
		base = 0

		modifier = {
			debt_level >= 0
			add = 100
		}

		modifier = {
			scope:actor.treasury_or_gold < 0
			add = 40
		}

		modifier = { # A Head of Faith calling on his own prelates is routine, not a sign of desperation
			add = 100
			scope:actor = {
				any_held_title = { is_head_of_faith = yes }
				treasury <= 750
			}
			scope:recipient = {
				is_ai = yes
			}
		}

		modifier = {
			add = 100
			scope:recipient = {
				is_ruler = no
				treasury_or_gold >= 50
			}
			scope:actor = {
				any_held_title = { has_clerical_region = yes }
				NOT = { faith.religious_head ?= this } # A Head of Faith keeps the restraint of their own clause above
			}
		}

		modifier = {
			scope:hook = yes
			add = 50
		}
	}
}

#Request white peace through the archbishop of your clerical region
request_white_peace_interaction = {
	category = interaction_category_religion
	icon = icon_clergy_enfore_white_peace
	interface_priority = 40
	common_interaction = no
	notification_text = request_white_peace_interaction_notification
	greeting = positive

	use_diplomatic_range = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes

	desc = request_white_peace_interaction_desc

	cooldown_against_recipient = { years = 5 }

	is_available = {
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			religion ?= religion:christianity_religion
			pam_clergy_interactions_faith_trigger = yes
			is_ruler = yes
			NOR = {
				government_has_flag = government_is_theocracy
				is_at_war_with = scope:recipient
			}
		}
		scope:recipient = {
			pam_request_legitimacy_priest_trigger = { CHARACTER = scope:puppet_or_actor }
			any_held_title = {
				has_clerical_region = yes
			}
		}
		pam_should_bother_clergy_interaction_trigger = { PRIEST = scope:recipient }
		# Those under an antipope ask them instead of the real Head of Faith
		trigger_if = {
			limit = {
				scope:recipient ?= scope:puppet_or_actor.faith.religious_head
			}
			scope:puppet_or_actor ?= { is_following_religious_head_challenger = no }
		}
	}

	populate_recipient_list = {
		scope:puppet_or_actor = {
			every_war_enemy = {
				limit = {
					pam_request_white_peace_enemy_trigger = yes
				}
				add_to_list = characters
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			clergy_interaction_generic_piety_level_or_puppet_req_trigger = yes
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
			}
			is_at_war = yes
			NOR = {
				has_trait = excommunicated
				has_character_modifier = promised_pilgrimage_to_clergy_modifier
			}
		}
		scope:recipient = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
				adult = yes
			}
			NOT = {
				has_trait = excommunicated
			}
			highest_held_title_tier >= tier_duchy
			custom_tooltip = {
				text = pam_clergy_arbiter_must_be_archbishop_or_hof_tt
				OR = {
					scope:puppet_or_actor.capital_county.clerical_region_title.holder ?= this
					scope:puppet_or_actor.religious_head_or_challenger ?= this
					scope:puppet_or_actor.faith.religious_head ?= this
					scope:puppet_or_actor.rite.head_of_rite ?= this
				}
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= pam_request_white_peace_cost_value
			}
		}
	}

	has_valid_target_showing_failures_only = {
		scope:secondary_recipient ?= {
			pam_request_white_peace_enemy_trigger = yes
			# Only a Head of Faith or Rite has authority to impose international peace among kings and above
			trigger_if = {
				limit = {
					top_liege != scope:puppet_or_actor.top_liege
					OR = {
						highest_held_title_tier >= tier_kingdom
						scope:puppet_or_actor.highest_held_title_tier >= tier_kingdom
					}
				}
				custom_tooltip = { # shared Head of Faith
					text = pam_request_white_peace_enemy_invalid_tt
					OR = {
						AND = {
							religious_head_or_challenger ?= scope:recipient
							scope:puppet_or_actor.religious_head_or_challenger ?= scope:recipient
						}
						AND = {
							faith.religious_head ?= scope:recipient
							scope:puppet_or_actor.faith.religious_head ?= scope:recipient
						}
						AND = {
							rite.head_of_rite ?= scope:recipient
							scope:puppet_or_actor.rite.head_of_rite ?= scope:recipient
						}
					}
				}
			}
		}
		scope:puppet_or_actor = {
			custom_tooltip = {
				text = request_white_peace_no_valid_war_tt
				any_character_war = {
					pam_request_white_peace_war_with_enemy_trigger = { ENEMY = scope:secondary_recipient }
				}
			}
		}
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				if = {
					limit = { pam_request_white_peace_cost_value > 0 }
					add_piety = {
						value = {
							add = pam_request_white_peace_cost_value
							max = piety
							multiply = -1
						}
					}
				}
			}
		}
		scope:puppet_or_actor = {
			request_white_peace_interaction_effect = yes
		}
	}

	on_decline = {
		if = {
			limit = {
				scope:recipient = {
					is_ai = no
				}
			}
			scope:puppet_or_actor = {
				add_opinion = {
					modifier = refusal_opinion
					target = scope:recipient
					opinion = -15
				}
			}
		}
	}

	cost = {
		piety = {
			value = pam_request_white_peace_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:puppet_or_actor
			object = scope:recipient
			scope:use_hook = yes
			scope:puppet_or_actor = { has_strong_hook = scope:recipient }
		}
	}

	send_options_exclusive = no

	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				trigger_if = {
					limit = {
						scope:actor = {
							is_ai = yes
						}
					}
					short_term_gold >= major_gold_value
				}
				trigger_else = {
					short_term_gold >= major_gold_value
				}
			}
		}
		flag = donate_faith
		localization = DONATE_TO_THE_FAITH_INTERACTION_OPTION
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				piety >= major_piety_value
			}
		}
		flag = offer_piety
		localization = PAM_CLERGY_ARBITRATION_OFFER_PIETY_OPTION
	}

	send_option = {
		is_valid = {
			NOT = {
				scope:recipient = {
					has_usable_hook = scope:puppet_or_actor
				}
			}
			scope:recipient = {
				can_add_hook = {
					target = scope:puppet_or_actor
					type = favor_hook
				}
			}
		}
		flag = offer_hook
		localization = OFFER_HOOK_INTERACTION_OPTION_CLERGY
	}

	send_option = {
		is_shown = {
			scope:recipient != scope:puppet_or_actor
		}
		is_valid = {
			scope:puppet_or_actor = {
				has_usable_hook = scope:recipient
			}
			trigger_if = {
				limit = {
					scope:recipient = {
						is_ai = no
					}
				}
				scope:actor = { is_ai = no }
			}
		}
		flag = use_hook
		localization = EDUCATION_HOOK
	}

	send_option = {
		is_shown = {
			pam_offer_pilgrimage_option_shown_trigger = { ACTOR = scope:puppet_or_actor }
		}
		is_valid = {
			pam_offer_pilgrimage_option_valid_trigger = { ACTOR = scope:puppet_or_actor }
		}
		flag = offer_pilgrimage
		localization = OFFER_PILGRIMAGE_INTERACTION_OPTION
	}

	ai_accept = {
		base = -10

		modifier = {
			add = 25
			desc = pam_sf_ear_of_clergy_accept_reason
			trigger = {
				scope:puppet_or_actor = { has_character_modifier = pam_sf_ear_of_clergy_modifier }
			}
		}

		modifier = {
			scope:use_hook = yes
			add = 200
			scope:puppet_or_actor = { NOT = { has_strong_hook = scope:recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}

		general_secular_to_ecclesiastic_acceptance_modifier = yes

		modifier = {
			add = {
				value = 25
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:puppet_or_actor.major_gold_value < scope:recipient.miniscule_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 50
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:puppet_or_actor.major_gold_value >= scope:recipient.miniscule_gold_value
			scope:puppet_or_actor.major_gold_value < scope:recipient.major_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 75
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			scope:puppet_or_actor.major_gold_value >= scope:recipient.major_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = 40
			scope:offer_piety = yes
			desc = PAM_CLERGY_ARBITRATION_OFFER_PIETY_OPTION_REASON
		}
		modifier = {
			add = {
				value = 20
				multiply = scope:puppet_or_actor.highest_held_title_tier
			}
			scope:offer_hook = yes
			desc = OFFER_HOOK_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = pam_offer_pilgrimage_acceptance_value
			scope:offer_pilgrimage = yes
			desc = OFFER_PILGRIMAGE_INTERACTION_OPTION_REASON
		}
		modifier = {
			scope:puppet_or_actor = {
				any_character_war = {
					pam_request_white_peace_war_with_enemy_trigger = { ENEMY = scope:secondary_recipient }
					OR = {
						AND = {
							casus_belli = {
								primary_attacker = scope:puppet_or_actor
							}
							defender_war_score >= 20
						}
						AND = {
							casus_belli = {
								primary_defender = scope:puppet_or_actor
							}
							attacker_war_score >= 20
						}
					}
				}
			}
			add = 25
			desc = REQUEST_WHITE_PEACE_ACTOR_LOSING_REASON
		}
		modifier = {
			scope:puppet_or_actor = {
				any_character_war = {
					pam_request_white_peace_war_with_enemy_trigger = { ENEMY = scope:secondary_recipient }
					war_days >= 1825
				}
			}
			add = 20
			desc = PAM_CLERGY_ARBITRATION_LONG_WAR_REASON
		}
		modifier = {
			pam_character_has_peaceful_tenet_trigger = { CHARACTER = scope:puppet_or_actor }
			add = 35
			desc = PAM_CLERGY_ARBITRATION_ACTOR_PEACEFUL_TENET_REASON
		}
		modifier = {
			pam_character_has_peaceful_tenet_trigger = { CHARACTER = scope:recipient }
			add = 45
			desc = PAM_CLERGY_ARBITRATION_RECIPIENT_PEACEFUL_TENET_REASON
		}
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:secondary_recipient
			multiplier = -0.5
			desc = AI_OPINION_REASON
		}
		modifier = {
			add = {
				value = -5
				multiply = scope:secondary_recipient.piety_level
			}
			scope:secondary_recipient.piety_level > 1
			desc = THEY_ARE_PIOUS
		}
		modifier = {
			add = {
				value = -5
				multiply = scope:secondary_recipient.num_virtuous_traits
			}
			scope:secondary_recipient.num_virtuous_traits > 0
			desc = THEY_ARE_VIRTUOUS
		}
		modifier = {
			add = {
				value = 5
				multiply = scope:secondary_recipient.num_sinful_traits
			}
			scope:secondary_recipient.num_sinful_traits > 0
			desc = THEY_ARE_SINFUL
		}
		modifier = {
			add = -50
			scope:recipient = {
				OR = {
					has_relation_friend = scope:secondary_recipient
					has_relation_lover = scope:secondary_recipient
					has_relation_best_friend = scope:secondary_recipient
				}
			}
			desc = PAM_CLERGY_ARBITRATION_FRIEND_OF_OPPONENT_REASON
		}
		modifier = {
			add = 50
			scope:recipient = {
				OR = {
					has_relation_rival = scope:secondary_recipient
					has_relation_nemesis = scope:secondary_recipient
				}
			}
			desc = PAM_CLERGY_ARBITRATION_RIVAL_OF_OPPONENT_REASON
		}
	}

	ai_targets = {
		ai_recipients = realm_priest_top_superior
		ai_recipients = head_of_faith
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 24
		duchy = 24
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_will_do = {
		base = 0

		modifier = {
			scope:puppet_or_actor = {
				any_character_war = {
					pam_request_white_peace_war_with_enemy_trigger = { ENEMY = scope:secondary_recipient }
					OR = {
						AND = {
							casus_belli = {
								primary_attacker = scope:puppet_or_actor
							}
							defender_war_score >= 30
						}
						AND = {
							casus_belli = {
								primary_defender = scope:puppet_or_actor
							}
							attacker_war_score >= 30
						}
					}
				}
			}
			add = 40
		}
		modifier = {
			scope:puppet_or_actor = {
				any_character_war = {
					pam_request_white_peace_war_with_enemy_trigger = { ENEMY = scope:secondary_recipient }
					war_days >= 1825
				}
			}
			add = 25
		}
		modifier = {
			scope:donate_faith = yes
			add = 15
		}
		modifier = {
			scope:offer_piety = yes
			add = 15
		}
		modifier = {
			scope:offer_hook = yes
			add = 15
		}
		# Send options alone must not make a winning or fresh war worth ending
		modifier = {
			factor = 0
			NOT = {
				scope:puppet_or_actor = {
					any_character_war = {
						pam_request_white_peace_war_with_enemy_trigger = { ENEMY = scope:secondary_recipient }
						OR = {
							war_days >= 1825
							AND = {
								casus_belli = {
									primary_attacker = scope:puppet_or_actor
								}
								defender_war_score >= 30
							}
							AND = {
								casus_belli = {
									primary_defender = scope:puppet_or_actor
								}
								attacker_war_score >= 30
							}
						}
					}
				}
			}
		}
	}
}


#Ask the clergy to rule an ongoing war won at 90% war score instead of 100%, with the Church compensating the loser
request_victory_interaction = {
	category = interaction_category_religion
	icon = icon_clergy_request_victory
	interface_priority = 41
	common_interaction = no
	notification_text = request_victory_interaction_notification
	greeting = positive

	use_diplomatic_range = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes

	desc = request_victory_interaction_desc

	#A ruling this favourable is a once-a-decade indulgence, not a war-by-war tool
	cooldown = { years = 10 }

	is_available = {
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			religion ?= religion:christianity_religion
			NOT = {
				government_has_flag = government_is_theocracy
			}
			pam_clergy_interactions_faith_trigger = yes
			is_ruler = yes
		}
		scope:puppet_or_actor ?= {
			NOT = {
				is_at_war_with = scope:recipient
			}
		}
		scope:recipient = {
			pam_request_legitimacy_priest_trigger = { CHARACTER = scope:puppet_or_actor }
			any_held_title = {
				has_clerical_region = yes
			}
			NOT = { this = scope:actor }
		}
		pam_should_bother_clergy_interaction_trigger = { PRIEST = scope:recipient }
		# Those under an antipope ask them instead of the real Head of Faith
		trigger_if = {
			limit = {
				scope:recipient ?= scope:puppet_or_actor.faith.religious_head
			}
			scope:puppet_or_actor ?= { is_following_religious_head_challenger = no }
		}
	}

	populate_recipient_list = {
		scope:puppet_or_actor = {
			every_war_enemy = {
				limit = {
					#The clergy can only press its own flock, so the eligible opponents are the same set as Request White Peace
					pam_request_white_peace_enemy_trigger = yes
				}
				add_to_list = characters
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			clergy_interaction_generic_piety_level_or_puppet_req_trigger = yes
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
			}
			is_at_war = yes
			NOR = {
				has_trait = excommunicated
				has_character_modifier = promised_pilgrimage_to_clergy_modifier
			}
		}
		scope:recipient = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
				adult = yes
			}
			NOT = {
				has_trait = excommunicated
			}
			highest_held_title_tier >= tier_duchy
			custom_tooltip = {
				text = pam_clergy_arbiter_must_be_archbishop_or_hof_tt
				OR = {
					scope:puppet_or_actor.capital_county.clerical_region_title.holder ?= this
					scope:puppet_or_actor.faith.religious_head ?= this
					scope:puppet_or_actor.religious_head_or_challenger ?= this
					scope:puppet_or_actor.rite.head_of_rite ?= this
				}
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= pam_request_victory_cost_value
			}
		}
	}

	has_valid_target_showing_failures_only = {
		scope:secondary_recipient ?= {
			pam_request_white_peace_enemy_trigger = yes
			# The arbiter needs authority over the opponent too, not just over the petitioner
			custom_tooltip = {
				text = pam_request_victory_enemy_invalid_tt
				OR = {
					AND = {
						religious_head_or_challenger ?= scope:recipient
						scope:puppet_or_actor.religious_head_or_challenger ?= scope:recipient
					}
					AND = {
						faith.religious_head ?= scope:recipient
						scope:puppet_or_actor.faith.religious_head ?= scope:recipient
					}
					AND = {
						rite.head_of_rite ?= scope:recipient
						scope:puppet_or_actor.rite.head_of_rite ?= scope:recipient
					}
					capital_county.clerical_region_title.holder ?= scope:recipient
				}
			}
			# Even a shared archdiocese does not let an archbishop rule on a war between crowns of separate realms
			trigger_if = {
				limit = {
					top_liege != scope:puppet_or_actor.top_liege
					OR = {
						highest_held_title_tier >= tier_kingdom
						scope:puppet_or_actor.highest_held_title_tier >= tier_kingdom
					}
				}
				custom_tooltip = {
					text = pam_request_victory_crowns_need_hof_tt
					OR = {
						religious_head_or_challenger ?= scope:recipient
						faith.religious_head ?= scope:recipient
						rite.head_of_rite ?= scope:recipient
					}
				}
			}
		}
		scope:puppet_or_actor = {
			custom_tooltip = {
				text = request_victory_no_valid_war_tt
				any_character_war = {
					pam_request_victory_war_with_enemy_trigger = { ENEMY = scope:secondary_recipient }
				}
			}
			custom_tooltip = {
				text = request_victory_already_won_tt
				NOT = {
					any_character_war = {
						pam_request_victory_war_already_won_trigger = { ENEMY = scope:secondary_recipient }
					}
				}
			}
		}
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				if = {
					limit = { pam_request_victory_cost_value > 0 }
					add_piety = {
						value = {
							add = pam_request_victory_cost_value
							max = piety
							multiply = -1
						}
					}
				}
			}
		}
		scope:puppet_or_actor = {
			request_victory_interaction_effect = yes
		}
	}

	on_decline = {
		if = {
			limit = {
				scope:recipient = {
					is_ai = no
				}
			}
			scope:puppet_or_actor = {
				add_opinion = {
					modifier = refusal_opinion
					target = scope:recipient
					opinion = -15
				}
			}
		}
	}

	cost = {
		piety = {
			value = pam_request_victory_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:puppet_or_actor
			object = scope:recipient
			scope:use_hook = yes
			scope:puppet_or_actor = { has_strong_hook = scope:recipient }
		}
	}

	send_options_exclusive = no

	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				short_term_gold >= major_gold_value
			}
		}
		flag = donate_faith
		localization = DONATE_TO_THE_FAITH_INTERACTION_OPTION
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				piety >= major_piety_value
			}
		}
		flag = offer_piety
		localization = PAM_CLERGY_ARBITRATION_OFFER_PIETY_OPTION
	}

	send_option = {
		is_valid = {
			NOT = {
				scope:recipient = {
					has_usable_hook = scope:puppet_or_actor
				}
			}
			scope:recipient = {
				can_add_hook = {
					target = scope:puppet_or_actor
					type = favor_hook
				}
			}
		}
		flag = offer_hook
		localization = OFFER_HOOK_INTERACTION_OPTION_CLERGY
	}

	send_option = {
		is_shown = {
			scope:recipient != scope:puppet_or_actor
		}
		is_valid = {
			scope:puppet_or_actor = {
				has_usable_hook = scope:recipient
			}
			trigger_if = {
				limit = {
					scope:recipient = {
						is_ai = no
					}
				}
				scope:actor = { is_ai = no }
			}
		}
		flag = use_hook
		localization = EDUCATION_HOOK
	}

	send_option = {
		is_shown = {
			pam_offer_pilgrimage_option_shown_trigger = { ACTOR = scope:puppet_or_actor }
		}
		is_valid = {
			pam_offer_pilgrimage_option_valid_trigger = { ACTOR = scope:puppet_or_actor }
		}
		flag = offer_pilgrimage
		localization = OFFER_PILGRIMAGE_INTERACTION_OPTION
	}

	should_use_extra_icon = {
		scope:puppet_or_actor = { has_usable_hook = scope:recipient }
	}

	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	ai_accept = {
		#Ruling on who wins a war is a far greater favour than mediating a truce
		base = -40

		modifier = {
			add = 25
			desc = pam_sf_ear_of_clergy_accept_reason
			trigger = {
				scope:puppet_or_actor = { has_character_modifier = pam_sf_ear_of_clergy_modifier }
			}
		}

		modifier = {
			scope:use_hook = yes
			add = 200
			scope:puppet_or_actor = { NOT = { has_strong_hook = scope:recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}

		general_secular_to_ecclesiastic_acceptance_modifier = yes

		modifier = {
			add = 25
			scope:donate_faith = yes
			scope:puppet_or_actor.major_gold_value < scope:recipient.miniscule_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = 50
			scope:donate_faith = yes
			scope:puppet_or_actor.major_gold_value >= scope:recipient.miniscule_gold_value
			scope:puppet_or_actor.major_gold_value < scope:recipient.major_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = 75
			scope:donate_faith = yes
			scope:puppet_or_actor.major_gold_value >= scope:recipient.major_gold_value
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = 40
			scope:offer_piety = yes
			desc = PAM_CLERGY_ARBITRATION_OFFER_PIETY_OPTION_REASON
		}
		modifier = {
			add = {
				value = 20
				multiply = scope:puppet_or_actor.highest_held_title_tier
			}
			scope:offer_hook = yes
			desc = OFFER_HOOK_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = pam_offer_pilgrimage_acceptance_value
			scope:offer_pilgrimage = yes
			desc = OFFER_PILGRIMAGE_INTERACTION_OPTION_REASON
		}
		#The closer the war is to won, the less the clergy is really deciding anything
		modifier = {
			scope:puppet_or_actor = {
				any_character_war = {
					pam_request_victory_war_with_enemy_trigger = { ENEMY = scope:secondary_recipient }
					OR = {
						AND = {
							casus_belli = {
								primary_attacker = scope:puppet_or_actor
							}
							attacker_war_score >= 95
						}
						AND = {
							casus_belli = {
								primary_defender = scope:puppet_or_actor
							}
							defender_war_score >= 95
						}
					}
				}
			}
			add = 20
			desc = REQUEST_VICTORY_WAR_ALL_BUT_WON_REASON
		}
		modifier = {
			scope:puppet_or_actor = {
				any_character_war = {
					pam_request_victory_war_with_enemy_trigger = { ENEMY = scope:secondary_recipient }
					war_days >= 1825
				}
			}
			add = 20
			desc = PAM_CLERGY_ARBITRATION_LONG_WAR_REASON
		}
		modifier = {
			pam_character_has_peaceful_tenet_trigger = { CHARACTER = scope:puppet_or_actor }
			add = 35
			desc = PAM_CLERGY_ARBITRATION_ACTOR_PEACEFUL_TENET_REASON
		}
		modifier = {
			pam_character_has_peaceful_tenet_trigger = { CHARACTER = scope:recipient }
			add = 45
			desc = PAM_CLERGY_ARBITRATION_RECIPIENT_PEACEFUL_TENET_REASON
		}
		modifier = {
			add = 40
			scope:secondary_recipient = {
				has_trait = excommunicated
			}
			desc = REQUEST_VICTORY_OPPONENT_EXCOMMUNICATED_REASON
		}
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:secondary_recipient
			multiplier = -0.5
			desc = AI_OPINION_REASON
		}
		modifier = {
			add = {
				value = -5
				multiply = scope:secondary_recipient.piety_level
			}
			scope:secondary_recipient.piety_level > 1
			desc = THEY_ARE_PIOUS
		}
		modifier = {
			add = {
				value = -5
				multiply = scope:secondary_recipient.num_virtuous_traits
			}
			scope:secondary_recipient.num_virtuous_traits > 0
			desc = THEY_ARE_VIRTUOUS
		}
		modifier = {
			add = {
				value = 5
				multiply = scope:secondary_recipient.num_sinful_traits
			}
			scope:secondary_recipient.num_sinful_traits > 0
			desc = THEY_ARE_SINFUL
		}
		modifier = {
			add = -50
			scope:recipient = {
				OR = {
					has_relation_friend = scope:secondary_recipient
					has_relation_lover = scope:secondary_recipient
					has_relation_best_friend = scope:secondary_recipient
				}
			}
			desc = PAM_CLERGY_ARBITRATION_FRIEND_OF_OPPONENT_REASON
		}
		modifier = {
			add = 50
			scope:recipient = {
				OR = {
					has_relation_rival = scope:secondary_recipient
					has_relation_nemesis = scope:secondary_recipient
				}
			}
			desc = PAM_CLERGY_ARBITRATION_RIVAL_OF_OPPONENT_REASON
		}
	}

	ai_targets = {
		ai_recipients = realm_priest_top_superior
		ai_recipients = head_of_faith
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 24
		duchy = 24
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_will_do = {
		base = 0

		modifier = {
			scope:puppet_or_actor = {
				any_character_war = {
					pam_request_victory_war_with_enemy_trigger = { ENEMY = scope:secondary_recipient }
				}
			}
			add = 50
		}
		modifier = {
			scope:puppet_or_actor = {
				any_character_war = {
					pam_request_victory_war_with_enemy_trigger = { ENEMY = scope:secondary_recipient }
					war_days >= 1825
				}
			}
			add = 25
		}
		modifier = {
			scope:donate_faith = yes
			add = 15
		}
		modifier = {
			scope:offer_piety = yes
			add = 15
		}
		modifier = {
			scope:offer_hook = yes
			add = 15
		}
	}
}


#Head of faith or head of rite creates a custom kingdom for a same-faith duke
ecclesiastic_consecrate_kingdom_interaction = {
	category = interaction_category_religion
	icon = icon_clergy_claim_unformed_kingdom
	notification_text = ECCLESIASTICAL_CONSECRATE_KINGDOM_NOTIFICATION
	interface_priority = 69
	common_interaction = yes
	popup_on_receive = yes

	desc = ecclesiastic_consecrate_kingdom_interaction_desc

	is_available = {
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			government_has_flag = government_is_theocracy
			is_available_quick = {
				adult = yes
				alive = yes
				imprisoned = no
				incapable = no
			}
		}
		exists = scope:puppet_or_actor
		scope:puppet_or_actor != scope:recipient
		scope:puppet_or_actor ?= {
			OR = {
				scope:recipient.religious_head_or_challenger ?= this
				AND = {
					highest_held_title_tier >= tier_duchy
					government_has_flag = government_is_theocracy
					NOT = { exists = scope:recipient.religious_head_or_challenger }
					scope:recipient.rite.head_of_rite ?= this
				}
			}
		}
		scope:recipient = {
			faith ?= scope:puppet_or_actor.faith
			is_landed = yes
			highest_held_title_tier = tier_duchy
			NOT = { has_game_rule = off_custom_kingdoms }
			is_confederation_member = no
			OR = {
				government_has_flag = government_is_theocracy
				has_legitimacy = yes
			}			
			NOT = {
				any_held_title = {
					tier = tier_duchy
					de_jure_liege ?= {
						tier = tier_kingdom
						NOT = { exists = holder }
						is_landless_type_title = no
					}
				}
			}
			trigger_if = {
				limit = {
					NOT = {
						scope:puppet_or_actor.religious_head_or_challenger ?= scope:puppet_or_actor
					}
				}
				rite = scope:puppet_or_actor.rite
			}
		}
		trigger_if = {
			limit = {
				scope:actor = {
					is_ai = yes
				}
			}
			scope:recipient = {
				piety_level >= 2
			}
			scope:puppet_or_actor ?= {
				NOT = {
					has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			piety_level >= 3
			trigger_if = {
				limit = {
					NOT = {
						religious_head_or_challenger ?= scope:puppet_or_actor
					}
					scope:recipient = {
						is_independent_ruler = no
					}
				}
        		custom_tooltip = {
					text = recipient_head_of_rite_is_not_lieges_head_of_rite_tt
					exists = scope:recipient.liege.rite.head_of_rite
					rite.head_of_rite ?= scope:recipient.liege.rite.head_of_rite
				}
        	}
        	NOT = {
        		has_trait = excommunicated
        	}
		}
		scope:recipient = {
			is_available_quick = {
				alive = yes
				incapable = no
				imprisoned = no
			}
			is_at_war = no
			faith = scope:puppet_or_actor.faith
			NOT = {
				has_trait = excommunicated
			}
			custom_tooltip = {
				text = must_hold_landed_duchy_tt
				any_held_title = {
					tier = tier_duchy
					is_landless_type_title = no
				}
			}
			custom_tooltip = {
				text = recipient_liege_is_emperor_or_none_tt
				OR = {
					is_independent_ruler = yes
					liege.highest_held_title_tier >= tier_empire
				}
			}
			trigger_if = {
				limit = {
					NOT = {
						scope:puppet_or_actor.religious_head_or_challenger ?= scope:puppet_or_actor
					}
				}
				rite = scope:puppet_or_actor.rite
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				gold >= pam_ecclesiastic_consecrate_kingdom_gold_cost_value
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				treasury >= pam_ecclesiastic_consecrate_kingdom_treasury_cost_value
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= pam_ecclesiastic_consecrate_kingdom_piety_cost_value
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				prestige >= pam_ecclesiastic_consecrate_kingdom_prestige_cost_value
			}
		}
	}

	cost = {
		gold = {
			value = pam_ecclesiastic_consecrate_kingdom_gold_cost_value
			if = {
				limit = {
					OR = {
						scope:is_puppet_action ?= yes
						scope:puppet_or_actor = { has_treasury = yes }
					}
				}
				multiply = 0
			}
		}
		treasury = {
			value = pam_ecclesiastic_consecrate_kingdom_treasury_cost_value
			if = {
				limit = {
					OR = {
						scope:is_puppet_action ?= yes
						scope:puppet_or_actor = { has_treasury = no }
					}
				}
				multiply = 0
			}
		}
		piety = {
			value = pam_ecclesiastic_consecrate_kingdom_piety_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
		prestige = {
			value = pam_ecclesiastic_consecrate_kingdom_prestige_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	options_heading = consecrate_kingdom_interaction_options
	send_options_exclusive = yes
	send_option = {
		is_valid = {
			custom_tooltip = {
				text = has_valid_exclave_duchy_tt
				scope:recipient = {
					 any_sub_realm_county = {
    				    kingdom = {
    				        any_direct_de_jure_vassal_title = {
    				            pam_custom_kingdom_can_claim_duchy_exclave_trigger = { NEW_KING = scope:recipient }
    				        }
    				    }
    				}
				}
			}
		}
		flag = newly_exclaved_duchies
		localization = CONSECRATE_CUSTOM_KINGDOM_WITH_EXCLAVES
	}
	send_option = {
		flag = only_sub_realm_duchies
		localization = CONSECRATE_CUSTOM_KINGDOM_WITHOUT_EXCLAVES
	}
	ai_accept = {
		base = 0
		
		modifier = { # Peace of God: a crown granted by the Church is a crown won without war
			scope:recipient.rite ?= {
				rite_has_parameter = tenet_peace_of_god_clergy_peacemaking
			}
			add = 40
			desc = pam_peace_of_god_clergy_peacemaking_accept_reason
		}
		modifier = {
			scope:recipient = {
				OR = {
					ai_energy > 0
					ai_energy < 0
				}
			}
			add = {
				value = scope:recipient.ai_energy
				multiply = 0.5
			} 
			desc = RECIPIENT_ENERGY_REASON
		}
		modifier = {
			scope:recipient = {
				OR = {
					ai_greed > 0
					ai_greed < 0
				}
			}
			add = {
				value = scope:recipient.ai_greed
				multiply = 0.5
			} 
			desc = RECIPIENT_GREED_REASON
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_1
			desc = ESTATE_PAPAL_VOTE_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_easier_papal_vote_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_2
			desc = ESTATE_PAPAL_VOTE_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_easier_papal_vote_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_3
			desc = ESTATE_PAPAL_VOTE_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_easier_papal_vote_3
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_value_1
			desc = ESTATE_ROYAL_NAVE_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_consecrate_nave_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_value_2
			desc = ESTATE_ROYAL_NAVE_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_consecrate_nave_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_value_3
			desc = ESTATE_ROYAL_NAVE_REASON
			scope:puppet_or_actor ?= {
				domicile ?= {
					has_domicile_parameter = estate_consecrate_nave_3
				}
			}
		}

		modifier = {
			scope:recipient = {
				is_independent_ruler = no
				OR = {
					opinion = {
						target = scope:recipient.liege
						value >= 25
					}
					has_dread_level_towards = {
						target = scope:recipient.liege
						level >= 1
					}
				}
				
			}
			add = {
				value = -30
				if = {
					limit = {
						scope:recipient = {
							opinion = {
								target = scope:recipient.liege
								value >= 80
							}
						}
					}
					add = -50
				}
				if = {
					limit = {
						scope:recipient = {
							has_dread_level_towards = {
								target = scope:recipient.liege
								level >= 1
							}
						}
					}
					add = -20
				}
				if = {
					limit = {
						scope:recipient = {
							has_dread_level_towards = {
								target = scope:recipient.liege
								level >= 2
							}
						}
					}
					add = -50
				}
			}
			desc = CONCERN_ABOUT_LIEGE_REASON
		}

		modifier = {
			scope:recipient ?= {
				ai_zeal != 0
			}
			add = scope:recipient.ai_zeal
			desc = RECIPIENT_ZEALOUSNESS_REASON
		}
		modifier = {
			add = -100
			scope:recipient = { has_trait = paranoid }
			desc = DEMAND_SUBMISSION_RECIPIENT_IS_PARANOID
		}
		modifier = {
			add = -100
			scope:recipient = { has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:puppet_or_actor } }
			desc = RECIPIENT_BAD_RELATIONS
		}
		modifier = {
			add = -25
			scope:recipient = {
				any_claim = {
					tier >= tier_kingdom
				}
			}
			desc = RECIPIENT_POWERFUL_CLAIMS
		}
		modifier = {
			add = -50
			scope:recipient = {
				any_heir_title = {
					tier >= tier_kingdom
					place_in_line_of_succession = {
						target = scope:recipient
						value = 1
					}
				}
			}
			desc = RECIPIENT_POWERFUL_HEIR
		}
		modifier = {
			add = 200
			scope:puppet_or_actor = {
				has_strong_hook = scope:recipient
			}
			desc = HAS_STRONG_HOOK_RECIPIENT_REASON
		}
		modifier = {
			add = 25
			scope:puppet_or_actor = {
				NOT = { has_strong_hook = scope:recipient }
				has_hook = scope:recipient
			}
			desc = HAS_HOOK_RECIPIENT_REASON
		}
		modifier = {
			add = 75
			scope:recipient = {
				government_has_flag = government_is_theocracy
			}
			desc = IS_THEOCRATIC_REASON
		}
		modifier = {
			add = 100
			scope:recipient = { has_any_good_relationship_with_character_trigger = { CHARACTER = scope:puppet_or_actor } }
			desc = RECIPIENT_GOOD_RELATIONS
		}
		modifier = {
			add = {
				value = scope:recipient.intrigue
				subtract = 12
				multiply = -10
			}
			scope:recipient.intrigue > 12
			desc = RECIPIENT_RESISTS_HOOK_REASON
		}
		modifier = {
			add = 300
			puppeteer ?= scope:puppet_or_actor
			desc = IS_YOUR_PUPPET_REASON
		}
		modifier = {
			add = 30
			scope:recipient = {
				is_vassal_or_below_of = scope:puppet_or_actor
			}
			desc = IS_YOUR_VASSAL_REASON
		}
		modifier = {
			add = {
				value = 50
				if = {
					limit = {
						scope:recipient.house.house_head = scope:puppet_or_actor
					}
					add = 50
				}
			}
			exists = scope:puppet_or_actor.house
			scope:recipient = {
				house ?= scope:puppet_or_actor.house
			}
			desc = OF_YOUR_HOUSE_REASON
		}
		modifier = {
			add = 20
			exists = scope:puppet_or_actor.dynasty
			scope:recipient = {
				dynasty ?= scope:puppet_or_actor.dynasty
			}
			desc = OF_YOUR_DYNASTY_REASON
		}
		modifier = {
			add = 60
			scope:recipient = {
				any_sub_realm_county = {
					any_neighboring_county = {
						holder.top_liege ?= {
							NOT = {
								faith = scope:puppet_or_actor.faith
							}
							scope:puppet_or_actor.rite = {
								rite_hostility_level = {
									target = prev.rite
									value >= faith_hostile_level
								}
							}
						}
					}
				}
			}
			desc = NEIGHBORS_HOSTILE_HEATHENS_REASON
		}
		opinion_modifier = {
			opinion_target = scope:puppet_or_actor
			who = scope:recipient
			multiplier = 1
			desc = AI_OPINION_REASON
		}
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				if = {
					limit = { pam_ecclesiastic_consecrate_kingdom_treasury_cost_value > 0 }
					remove_treasury = pam_ecclesiastic_consecrate_kingdom_treasury_cost_value
				}
				if = {
					limit = { pam_ecclesiastic_consecrate_kingdom_gold_cost_value > 0 }
					remove_short_term_gold = {
						value = pam_ecclesiastic_consecrate_kingdom_gold_cost_value
					}
				}
				if = {
					limit = { pam_ecclesiastic_consecrate_kingdom_piety_cost_value > 0 }
					add_piety = {
						value = {
							add = pam_ecclesiastic_consecrate_kingdom_piety_cost_value
							max = piety
							multiply = -1
						}
					}
				}
				if = {
					limit = { pam_ecclesiastic_consecrate_kingdom_prestige_cost_value > 0 }
					add_prestige = {
						value = {
							add = pam_ecclesiastic_consecrate_kingdom_prestige_cost_value
							max = prestige
							multiply = -1
						}
					}
				}
			}
		}
		scope:puppet_or_actor = {
			save_scope_as = religious_authority
			save_scope_as = interaction
		}
		scope:recipient = {
			save_scope_as = king_aspirant
			show_as_tooltip = {
				consecrate_kingdom_player_cleric_effect = yes
				consecrate_kingdom_effect = yes
			}
		}
		#Opinion effects
		grant_title_populate_concerned_de_jure_list_effect = { TITLE_GAINER = scope:king_aspirant }
		#Show opinion losses to relevant characters
		if = {
			limit = {
				scope:actor = {
					is_ai = no
				}
			}
			every_in_list = {
				list = grateful_refusal_chars
				add_opinion = {
					target = scope:puppet_or_actor
					modifier = gave_away_de_jure_lands_opinion
					opinion = -50
				}
			}
			if = {
				limit = {
					scope:king_aspirant = {
						is_independent_ruler = no
						liege = {
							NOR = {
								is_in_list = grateful_refusal_chars
								this = scope:puppet_or_actor
							}
						}
					}
				}
				scope:king_aspirant.liege = {
					add_opinion = {
						target = scope:puppet_or_actor
						modifier = circumvented_my_authority_opinion
						opinion = -50
					}
				}
			}
		}
		else = {
			hidden_effect = {
				every_in_list = {
					list = grateful_refusal_chars
					add_opinion = {
						target = scope:puppet_or_actor
						modifier = gave_away_de_jure_lands_opinion
						opinion = -50
					}
				}
				if = {
					limit = {
						scope:king_aspirant = {
							is_independent_ruler = no
							liege = {
								NOR = {
									is_in_list = grateful_refusal_chars
									this = scope:puppet_or_actor
								}
							}
						}
					}
					scope:king_aspirant.liege = {
						add_opinion = {
							target = scope:puppet_or_actor
							modifier = circumvented_my_authority_opinion
							opinion = -50
						}
					}
				}
			}
		}
		if = {
			limit = {
				scope:king_aspirant = {
					is_ai = no
				}
			}
			every_in_list = {
				list = grateful_refusal_chars
				add_opinion = {
					target = scope:king_aspirant
					modifier = absorbed_de_jure_opinion
					opinion = -30
				}
			}
			if = {
				limit = {
					scope:king_aspirant = {
						is_independent_ruler = no
						liege = {
							NOR = {
								is_in_list = grateful_refusal_chars
								this = scope:puppet_or_actor
							}
						}
					}
				}
				scope:king_aspirant.liege = {
					add_opinion = {
						target = scope:king_aspirant
						modifier = circumvented_my_authority_opinion
						opinion = -30
					}
				}
			}
		}
		else = {
			hidden_effect = {
				every_in_list = {
					list = grateful_refusal_chars
					add_opinion = {
						target = scope:king_aspirant
						modifier = absorbed_de_jure_opinion
						opinion = -20
					}
				}
				if = {
					limit = {
						scope:king_aspirant = {
							is_independent_ruler = no
							liege = {
								NOR = {
									is_in_list = grateful_refusal_chars
									this = scope:puppet_or_actor
								}
							}
						}
					}
					scope:king_aspirant.liege = {
						add_opinion = {
							target = scope:king_aspirant
							modifier = circumvented_my_authority_opinion
							opinion = -20
						}
					}
				}
			}
		}
		
		scope:puppet_or_actor = {
			trigger_event = pam_interactions_events.0090
		}
	}
	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = ecclesiastic_title_refusal_toast_tt
				left_icon = scope:recipient
			}
		}
		grant_title_populate_concerned_de_jure_list_effect = { TITLE_GAINER = scope:recipient }
		if = {
			limit = {
				scope:recipient = {
					is_ai = no
				}
			}
			if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				scope:puppet_or_actor = {
				add_opinion = {
						modifier = refusal_opinion
						target = scope:recipient
						opinion = -40
					}
				}
			}
			every_in_list = {
				list = grateful_refusal_chars
				add_opinion = {
					target = scope:recipient
					modifier = respected_de_jure_opinion
					opinion = 20
				}
			}
			if = {
				limit = {
					scope:recipient = {
						is_independent_ruler = no
						liege = {
							NOR = {
								is_in_list = grateful_refusal_chars
								this = scope:puppet_or_actor
							}
						}
					}
				}
				scope:recipient.liege = {
					add_opinion = {
						target = scope:recipient
						modifier = loyalty_opinion
						opinion = 20
					}
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = neighboring_rulers_including_tributary_borders
		ai_recipients = dynasty
		ai_recipients = realm_characters
		ai_recipients = subordinates
		ai_recipients = rulers_in_clerical_region
		max = 5
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 60
		kingdom = 0
		empire = 0
		hegemony = 0
	}
	ai_will_do = {
		base = 0

		modifier = { # Peace of God: raising a crown by consecration is the Church's preferred alternative to conquest
			add = 25
			scope:puppet_or_actor.rite ?= {
				rite_has_parameter = tenet_peace_of_god_clergy_peacemaking
			}
		}

		modifier = {
			add = 10
			scope:recipient = {
				government_has_flag = government_is_theocracy
			}
		}

		modifier = {
			add = 100
			puppeteer ?= scope:puppet_or_actor
		}

		modifier = {
			exists = scope:puppet_or_actor.house
			scope:recipient = {
				house ?= scope:puppet_or_actor.house
			}
			add = 10
		}
		modifier = {
			add = 5
			exists = scope:puppet_or_actor.dynasty
			scope:recipient = {
				dynasty ?= scope:puppet_or_actor.dynasty
			}
		}
		modifier = {
			add = 20
			scope:recipient = {
				any_sub_realm_county = {
					any_neighboring_county = {
						holder.top_liege ?= {
							NOT = {
								faith = scope:puppet_or_actor.faith
							}
							scope:puppet_or_actor.rite = {
								rite_hostility_level = {
									target = prev.rite
									value >= faith_hostile_level
								}
							}
						}
					}
				}
			}
		}
		modifier = {
			add = {
				value = scope:recipient.piety_level
				multiply = 10
			}
		}
		opinion_modifier = {
			opinion_target = scope:recipient
			who = scope:actor
			multiplier = 0.5
		}
		modifier = {
			scope:recipient = {
				is_independent_ruler = no
			}
			scope:puppet_or_actor = {
				opinion = {
					target = scope:recipient.liege
					value >= 30
				}
			}
			add = -50
		}
		modifier = {
			scope:recipient = {
				is_independent_ruler = no
			}
			scope:puppet_or_actor = {
				opinion = {
					target = scope:recipient.liege
					value <= -50
				}
			}
			add = 10
		}
		modifier = {
			scope:recipient = {
				is_independent_ruler = no
			}
			scope:puppet_or_actor = {
				opinion = {
					target = scope:recipient.liege
					value <= -100
				}
			}
			add = 25
		}
		modifier = {
			add = -80
			scope:recipient = {
				sub_realm_size <= 1
			}
		}
		modifier = {
			add = -60
			scope:recipient = {
				sub_realm_size <= 3
				sub_realm_size > 1
			}
		}
		modifier = {
			add = -40
			scope:recipient = {
				sub_realm_size <= 6
				sub_realm_size > 3
			}
		}
		modifier = {
			add = -20
			scope:recipient = {
				sub_realm_size <= 9
				sub_realm_size > 6
			}
		}
		modifier = {
			add = -10
			scope:recipient = {
				sub_realm_size <= 12
				sub_realm_size > 9
			}
		}

		modifier = {
			add = 25
			scope:puppet_or_actor = { has_any_good_relationship_with_character_trigger = { CHARACTER = scope:recipient } }
		}
	}
}

#Head of faith or head of rite bestows an unheld de jure liege title
ecclesiastical_bestow_title_interaction = {
	category = interaction_category_religion
	icon = icon_clergy_claim_unformed_kingdom
	notification_text = ECCLESIASTICAL_BESTOW_TITLE_NOTIFICATION
	interface_priority = 69
	common_interaction = yes
	target_type = title
	target_filter = dejure_titles
	target_source = recipient
	show_all_targets = yes
	popup_on_receive = yes

	desc = ecclesiastical_bestow_title_interaction_desc

	is_available = {
		has_pam_dlc_trigger = yes
	}
	cost = {
		gold = {
			value = pam_ecclesiastical_bestow_title_gold_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
		treasury = {
			value = pam_ecclesiastical_bestow_title_treasury_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
		piety = {
			value = pam_ecclesiastical_bestow_title_piety_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			government_has_flag = government_is_theocracy
			is_available_quick = {
				adult = yes
				alive = yes
				imprisoned = no
				incapable = no
			}
		}
		scope:puppet_or_actor != scope:recipient
		scope:puppet_or_actor ?= {
			trigger_if = {
				limit = { exists = scope:recipient.religious_head_or_challenger }
				scope:recipient.religious_head_or_challenger = this
			}
			trigger_else = {
				highest_held_title_tier >= tier_duchy
				government_has_flag = government_is_theocracy
				scope:recipient.rite.head_of_rite ?= this
			}
		}
		scope:recipient = {
			is_landed = yes
			highest_held_title_tier >= tier_county
			highest_held_title_tier < tier_empire
			faith ?= scope:puppet_or_actor.faith
			any_held_title = {
				de_jure_liege ?= {
					tier < tier_hegemony
					NOT = { exists = holder }
					is_landless_type_title = no
				}
			}
		}
	}

	can_be_picked_title = {
		scope:target = {
			tier > tier_county
			custom_tooltip = {
				text = no_bestowing_hegemony_tt
				tier < tier_hegemony
			}
			custom_tooltip = {
				text = must_be_same_tier_or_one_higher_tt
				NOR = {
					tier > scope:recipient.highest_held_title_tier_plus_one
					tier < scope:recipient.highest_held_title_tier
				}
			}
			custom_tooltip = {
				text = target_has_holder_tt
				NOT = { exists = holder }
			}
			is_landless_type_title = no
		}
		scope:recipient = {
			any_held_title = {
				de_jure_liege = scope:target
			}
		}
	}

	has_valid_target_showing_failures_only = {
		exists = scope:target
		scope:target = {
			tier >= scope:recipient.highest_held_title_tier
			tier > tier_county
			is_landless_type_title = no
		}
		scope:recipient = {
			any_held_title = {
				de_jure_liege = scope:target
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			piety_level >= 2
			trigger_if = {
				limit = {
					NOT = {
						religious_head_or_challenger ?= scope:puppet_or_actor
					}
					scope:recipient = {
						is_independent_ruler = no
					}
				}
        		custom_tooltip = {
					text = recipient_head_of_rite_is_not_lieges_head_of_rite_tt
					exists = scope:recipient.liege.rite.head_of_rite
					rite.head_of_rite ?= scope:recipient.liege.rite.head_of_rite
				}
        	}
        	NOT = {
        		has_trait = excommunicated
        	}
		}
		scope:recipient = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				ruler = yes
			}
			NOT = {
				has_trait = excommunicated
			}
			faith = scope:puppet_or_actor.faith
			highest_held_title_tier >= tier_county
			custom_tooltip = {
				text = recipient_can_recieve_titles_normally_tt
				NOT = {
					is_vassal_or_below_of = scope:puppet_or_actor
				}
			}
			custom_tooltip = {
				text = recipient_liege_is_two_tiers_higher_or_none_tt
				OR = {
					is_independent_ruler = yes
					highest_held_title_tier < liege.highest_held_title_tier_minus_one
				}
			}
			trigger_if = {
				limit = {
					NOT = {
						scope:puppet_or_actor.religious_head_or_challenger ?= scope:puppet_or_actor
					}
				}
				rite = scope:puppet_or_actor.rite
			}
			custom_tooltip = {
				text = any_available_title_same_tier_or_higher_tt
				scope:recipient = {
					any_held_title = {
						de_jure_liege ?= {
							tier < tier_hegemony
							tier >= scope:recipient.highest_held_title_tier
							NOT = { exists = holder }
							is_landless_type_title = no
						}
					}
				}
			}

		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				gold >= pam_ecclesiastical_bestow_title_gold_cost_value
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				treasury >= pam_ecclesiastical_bestow_title_treasury_cost_value
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= pam_ecclesiastical_bestow_title_piety_cost_value
			}
		}
	}

	# A title handed over with no strings attached is never refused; the hook demands still go through ai_accept.
	auto_accept = {
		custom_description = {
			text = ecclesiastical_bestow_title_asks_nothing_tt
			scope:demand_nothing = yes
		}
	}

	send_options_exclusive = yes
	send_option = {
		is_valid = {
			scope:actor = {
				NOT = {
					has_strong_hook = scope:recipient
				}
				trigger_if = {
					limit = { is_ai = yes }
					ai_greed >= medium_positive_ai_value
				}
			}
		}
		flag = gain_strong_hook
		localization = GAIN_STRONG_HOOK_INTERACTION_OPTION
	}
	send_option = {
		is_valid = {
			scope:actor = {
				NOT = {
					has_hook = scope:recipient
				}
				trigger_if = {
					limit = { is_ai = yes }
					ai_greed > low_negative_ai_value
				}
			}
		}
		flag = gain_weak_hook
		localization = GAIN_WEAK_HOOK_INTERACTION_OPTION
	}
	send_option = {
		flag = demand_nothing
		localization = DEMAND_NOTHING_INTERACTION_OPTION
		starts_enabled = { always = yes }
	}
	ai_accept = {
		base = 100
		
		modifier = { # Peace of God: a title bestowed by the Church is a title not fought over
			scope:recipient.rite ?= {
				rite_has_parameter = tenet_peace_of_god_clergy_peacemaking
			}
			add = 40
			desc = pam_peace_of_god_clergy_peacemaking_accept_reason
		}
		modifier = {
			scope:recipient = {
				OR = {
					ai_energy > 0
					ai_energy < 0
				}
			}
			add = {
				value = scope:recipient.ai_energy
				multiply = 0.25
			} 
			desc = RECIPIENT_ENERGY_REASON
		}
		modifier = {
			scope:recipient = {
				OR = {
					ai_greed > 0
					ai_greed < 0
				}
			}
			add = {
				value = scope:recipient.ai_greed
				multiply = 0.25
			} 
			desc = RECIPIENT_GREED_REASON
		}

		modifier = {
			scope:recipient = {
				is_independent_ruler = no
				OR = {
					opinion = {
						target = scope:recipient.liege
						value >= 25
					}
					has_dread_level_towards = {
						target = scope:recipient.liege
						level >= 1
					}
				}
				
			}
			add = {
				value = -30
				if = {
					limit = {
						scope:recipient = {
							opinion = {
								target = scope:recipient.liege
								value >= 80
							}
						}
					}
					add = -50
				}
				if = {
					limit = {
						scope:recipient = {
							has_dread_level_towards = {
								target = scope:recipient.liege
								level >= 1
							}
						}
					}
					add = -20
				}
				if = {
					limit = {
						scope:recipient = {
							has_dread_level_towards = {
								target = scope:recipient.liege
								level >= 2
							}
						}
					}
					add = -50
				}
			}
			desc = CONCERN_ABOUT_LIEGE_REASON
		}

		modifier = {
			scope:recipient ?= {
				ai_zeal != 0
			}
			
			add = {
				value = scope:recipient.ai_zeal
				multiply = 0.5
			}
			desc = RECIPIENT_ZEALOUSNESS_REASON
		}
		modifier = {
			add = -100
			scope:recipient = { has_trait = paranoid }
			desc = DEMAND_SUBMISSION_RECIPIENT_IS_PARANOID
		}
		modifier = {
			add = -100
			scope:recipient = { has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:puppet_or_actor } }
			desc = RECIPIENT_BAD_RELATIONS
		}
		modifier = {
			add = -10
			exists = scope:target
			scope:recipient = {
				any_claim = {
					tier >= scope:target.tier
				}
			}
			desc = RECIPIENT_POWERFUL_CLAIMS
		}
		modifier = {
			add = 75
			exists = scope:target
			scope:recipient = {
				any_claim = {
					this = scope:target
				}
			}
			desc = RECIPIENT_CLAIMS_TARGET
		}
		modifier = {
			add = -50
			scope:recipient = {
				any_heir_title = {
					tier >= tier_kingdom
					place_in_line_of_succession = {
						target = scope:recipient
						value = 1
					}
				}
			}
			desc = RECIPIENT_POWERFUL_HEIR
		}
		modifier = {
			add = 200
			scope:puppet_or_actor = {
				has_strong_hook = scope:recipient
			}
			desc = HAS_STRONG_HOOK_RECIPIENT_REASON
		}
		modifier = {
			add = 25
			scope:puppet_or_actor = {
				NOT = { has_strong_hook = scope:recipient }
				has_hook = scope:recipient
			}
			desc = HAS_HOOK_RECIPIENT_REASON
		}
		modifier = {
			add = 75
			scope:recipient = {
				government_has_flag = government_is_theocracy
			}
			desc = IS_THEOCRATIC_REASON
		}
		modifier = {
			add = 100
			scope:recipient = { has_any_good_relationship_with_character_trigger = { CHARACTER = scope:puppet_or_actor } }
			desc = RECIPIENT_GOOD_RELATIONS
		}
		modifier = {
			add = {
				value = scope:recipient.intrigue
				subtract = 12
				multiply = -10
			}
			scope:recipient.intrigue > 12
			desc = RECIPIENT_RESISTS_HOOK_REASON
		}
		modifier = {
			add = 300
			puppeteer ?= scope:puppet_or_actor
			desc = IS_YOUR_PUPPET_REASON
		}
		modifier = {
			add = {
				value = 50
				if = {
					limit = {
						scope:recipient.house.house_head = scope:puppet_or_actor
					}
					add = 50
				}
			}
			exists = scope:puppet_or_actor.house
			scope:recipient = {
				house ?= scope:puppet_or_actor.house
			}
			desc = OF_YOUR_HOUSE_REASON
		}
		modifier = {
			add = 20
			exists = scope:puppet_or_actor.dynasty
			scope:recipient = {
				dynasty ?= scope:puppet_or_actor.dynasty
			}
			desc = OF_YOUR_DYNASTY_REASON
		}
		modifier = {
			add = 40
			scope:recipient = {
				any_sub_realm_county = {
					any_neighboring_county = {
						holder.top_liege ?= {
							NOT = {
								faith = scope:puppet_or_actor.faith
							}
							scope:puppet_or_actor.rite = {
								rite_hostility_level = {
									target = prev.rite
									value >= faith_hostile_level
								}
							}
						}
					}
				}
			}
			desc = NEIGHBORS_HOSTILE_HEATHENS_REASON
		}
		opinion_modifier = {
			opinion_target = scope:puppet_or_actor
			who = scope:recipient
			multiplier = 1
			desc = AI_OPINION_REASON
		}
		modifier = {
			add = -100
			scope:gain_weak_hook ?= yes
			desc = GAIN_WEAK_HOOK_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = -250
			scope:gain_strong_hook ?= yes
			desc = GAIN_STRONG_HOOK_INTERACTION_OPTION_REASON
		}
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				if = {
					limit = { pam_ecclesiastical_bestow_title_treasury_cost_value > 0 }
					remove_treasury = pam_ecclesiastical_bestow_title_treasury_cost_value
				}
				if = {
					limit = { pam_ecclesiastical_bestow_title_gold_cost_value > 0 }
					remove_short_term_gold = {
						value = pam_ecclesiastical_bestow_title_gold_cost_value
					}
				}
				if = {
					limit = { pam_ecclesiastical_bestow_title_piety_cost_value > 0 }
					add_piety = {
						value = {
							add = pam_ecclesiastical_bestow_title_piety_cost_value
							max = piety
							multiply = -1
						}
					}
				}
			}
		}
		scope:puppet_or_actor = {
			save_scope_as = religious_authority
		}
		#Show opinion losses to relevant characters
		if = {
			limit = {
				scope:actor = {
					is_ai = no
				}
			}
			if = {
				limit = {
					scope:recipient = {
						is_independent_ruler = no
						liege = {
							NOT = {
								this = scope:puppet_or_actor
							}
						}
					}
				}
				scope:recipient.liege = {
					add_opinion = {
						target = scope:puppet_or_actor
						modifier = circumvented_my_authority_opinion
						opinion = {
							value = -25
							if = {
								limit = {
									exists = scope:target
									scope:target.tier = scope:recipient.liege.highest_held_title_tier_minus_one
								}
								add = -25
							}
						}
					}
				}
			}
		}
		else = {
			hidden_effect = {
				if = {
					limit = {
						scope:recipient = {
							liege = {
								NOT = {
									this = scope:puppet_or_actor
								}
							}
						}
					}
					scope:recipient.liege = {
						add_opinion = {
							target = scope:puppet_or_actor
							modifier = circumvented_my_authority_opinion
							opinion = {
								value = -25
								if = {
									limit = {
										exists = scope:target
										scope:target.tier = scope:recipient.liege.highest_held_title_tier_minus_one
									}
									add = -25
								}
							}
						}
					}
				}
			}
		}
		if = {
			limit = {
				scope:recipient = {
					is_ai = no
				}
			}
			if = {
				limit = {
					scope:recipient = {
						is_independent_ruler = no
						liege = {
							NOT = {
								this = scope:puppet_or_actor
							}
						}
					}
				}
				scope:recipient.liege = {
					add_opinion = {
						target = scope:recipient
						modifier = circumvented_my_authority_opinion
						opinion = {
							value = -15
							if = {
								limit = {
									exists = scope:target
									scope:target.tier = scope:recipient.liege.highest_held_title_tier_minus_one
								}
								add = -15
							}
						}
					}
				}
			}
		}
		else = {
			hidden_effect = {
				if = {
					limit = {
						scope:recipient = {
							is_independent_ruler = no
							liege = {
								NOT = {
									this = scope:puppet_or_actor
								}
							}
						}
					}
					scope:recipient.liege = {
						add_opinion = {
							target = scope:recipient
							modifier = circumvented_my_authority_opinion
							opinion = {
								value = -10
								if = {
									limit = {
										exists = scope:target
										scope:target.tier = scope:recipient.liege.highest_held_title_tier_minus_one
									}
									add = -10
								}
							}
						}
					}
				}
			}
		}
		scope:recipient = {
			show_as_tooltip = { bestow_title_effect = yes }
		}
		scope:puppet_or_actor = {
			trigger_event = pam_interactions_events.0091
		}
	}
	on_decline = {
		if = {
			limit = {
				scope:recipient = {
					is_ai = no
				}
				scope:actor = { is_ai = yes }
			}
			scope:puppet_or_actor = {
				if = {
					limit = {
						exists = scope:target
					}
					add_opinion = {
						modifier = refusal_opinion
						target = scope:recipient
						opinion = {
							value = -25
							multiply = {
								value = scope:target.tier
								subtract = 2
							}
						}
					}
				}
				else = {
					add_opinion = {
						modifier = refusal_opinion
						target = scope:recipient
						opinion = -50
					}
				}
			}
			if = {
				limit = {
					scope:recipient = {
						is_independent_ruler = no
						liege = {
							NOT = {
								this = scope:puppet_or_actor
							}
						}
					}
				}
				scope:recipient.liege = {
					add_opinion = {
						target = scope:recipient
						modifier = loyalty_opinion
						opinion = {
							value = 10
							if = {
								limit = {
									exists = scope:target
									scope:target.tier = scope:recipient.liege.highest_held_title_tier_minus_one
								}
								add = 10
							}
						}
					}
				}
			}
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = ecclesiastic_title_refusal_toast_tt
				left_icon = scope:recipient
			}
		}
	}

	ai_targets = {
		ai_recipients = neighboring_rulers_including_tributary_borders
		ai_recipients = dynasty
		ai_recipients = realm_characters
		ai_recipients = subordinates
		ai_recipients = rulers_in_clerical_region
		max = 5
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 60
		duchy = 120
		kingdom = 240
		empire = 0
		hegemony = 0
	}
	ai_will_do = {
		base = 20

		modifier = { # Peace of God: the Church would rather settle a title than watch it be fought over
			add = 25
			scope:puppet_or_actor.rite ?= {
				rite_has_parameter = tenet_peace_of_god_clergy_peacemaking
			}
		}

		modifier = {
			add = 10
			scope:recipient = {
				government_has_flag = government_is_theocracy
			}
		}

		modifier = {
			add = 100
			puppeteer ?= scope:puppet_or_actor
		}

		modifier = {
			exists = scope:puppet_or_actor.house
			scope:recipient = {
				house ?= scope:puppet_or_actor.house
			}
			add = 10
		}
		modifier = {
			add = 5
			exists = scope:puppet_or_actor.dynasty
			scope:recipient = {
				dynasty ?= scope:puppet_or_actor.dynasty
			}
		}
		modifier = {
			add = 20
			scope:recipient = {
				any_sub_realm_county = {
					any_neighboring_county = {
						holder.top_liege ?= {
							NOT = {
								faith = scope:puppet_or_actor.faith
							}
							scope:puppet_or_actor.rite = {
								rite_hostility_level = {
									target = prev.rite
									value >= faith_hostile_level
								}
							}
						}
					}
				}
			}
		}
		modifier = {
			add = {
				value = scope:recipient.piety_level
				multiply = 10
			}
		}
		opinion_modifier = {
			opinion_target = scope:recipient
			who = scope:actor
			multiplier = 0.5
		}
		modifier = {
			scope:recipient = {
				is_independent_ruler = no
			}
			scope:puppet_or_actor = {
				opinion = {
					target = scope:recipient.liege
					value >= 30
				}
			}
			add = -50
		}
		modifier = {
			scope:recipient = {
				is_independent_ruler = no
			}
			scope:puppet_or_actor = {
				opinion = {
					target = scope:recipient.liege
					value <= -50
				}
			}
			add = 10
		}
		modifier = {
			scope:recipient = {
				is_independent_ruler = no
			}
			scope:puppet_or_actor = {
				opinion = {
					target = scope:recipient.liege
					value <= -100
				}
			}
			add = 25
		}
		modifier = {
			add = -80
			exists = scope:target
			scope:target.tier >= tier_empire
			scope:recipient = {
				sub_realm_size <= 10
			}
		}
		modifier = {
			add = -50
			exists = scope:target
			scope:target.tier >= tier_empire
			scope:recipient = {
				sub_realm_size <= 20
				sub_realm_size > 10
			}
		}
		modifier = {
			add = -20
			exists = scope:target
			scope:target.tier >= tier_empire
			scope:recipient = {
				sub_realm_size <= 30
				sub_realm_size > 20
			}
		}
		modifier = {
			add = -10
			exists = scope:target
			scope:target.tier >= tier_empire
			scope:recipient = {
				sub_realm_size <= 40
				sub_realm_size > 30
			}
		}
		modifier = {
			add = -5
			exists = scope:target
			scope:target.tier >= tier_empire
			scope:recipient = {
				sub_realm_size <= 50
				sub_realm_size > 40
			}
		}
		modifier = {
			add = -80
			exists = scope:target
			scope:target.tier >= tier_kingdom
			scope:recipient = {
				sub_realm_size <= 1
			}
		}
		modifier = {
			add = -50
			exists = scope:target
			scope:target.tier >= tier_kingdom
			scope:recipient = {
				sub_realm_size <= 3
				sub_realm_size > 1
			}
		}
		modifier = {
			add = -20
			exists = scope:target
			scope:target.tier >= tier_kingdom
			scope:recipient = {
				sub_realm_size <= 6
				sub_realm_size > 3
			}
		}
		modifier = {
			add = -10
			exists = scope:target
			scope:target.tier >= tier_kingdom
			scope:recipient = {
				sub_realm_size <= 9
				sub_realm_size > 6
			}
		}
		modifier = {
			add = -5
			exists = scope:target
			scope:target.tier >= tier_kingdom
			scope:recipient = {
				sub_realm_size <= 12
				sub_realm_size > 9
			}
		}

		modifier = {
			add = 25
			scope:puppet_or_actor = { has_any_good_relationship_with_character_trigger = { CHARACTER = scope:recipient } }
		}
		modifier = {
			save_temporary_scope_as = cleric
			add = {
				value = scope:recipient.clerical_hesitation_claim_interaction_value
				multiply = -5
			}
		}
	}
}

#Secular rulers petition the clergy to proclaim an unheld de jure title above their own and crown them with it
request_unformed_title_interaction = {
	category = interaction_category_religion
	icon = icon_clergy_claim_unformed_kingdom

	interface_priority = 40
	common_interaction = no
	target_type = title
	target_filter = dejure_titles
	target_source = actor
	show_all_targets = yes
	notification_text = REQUEST_UNFORMED_TITLE_NOTIFICATION
	greeting = positive

	use_diplomatic_range = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes

	desc = request_unformed_title_interaction_desc

	cooldown_against_recipient = { years = 10 }

	is_available = {
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			highest_held_title_tier >= tier_county
			is_landed = yes
			pam_clergy_interactions_faith_trigger = yes
			NOT = { government_has_flag = government_is_theocracy }
			highest_held_title_tier < tier_empire
			is_ruler = yes
		}
		scope:puppet_or_actor != scope:recipient
		scope:puppet_or_actor ?= {
			NOT = { is_at_war_with = scope:recipient }
			any_held_title = {
				de_jure_liege ?= {
					NOT = { exists = holder }
					tier < tier_hegemony
					is_landless_type_title = no
				}
			}
		}
		scope:recipient = {
			pam_request_legitimacy_priest_trigger = { CHARACTER = scope:puppet_or_actor }
			NOT = { this = scope:actor }
		}
	}

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			is_at_war = no
			clergy_interaction_generic_piety_level_or_puppet_req_trigger = yes
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
			}
			is_landed = yes
			NOT = {
				has_trait = excommunicated
			}
			primary_title = {
				is_landless_type_title = no
			}
			custom_tooltip = {
				text = request_unformed_title_not_clerics_vassal_tt
				NOT = {
					is_vassal_or_below_of = scope:recipient
				}
			}
			custom_tooltip = {
				text = request_unformed_title_liege_two_tiers_higher_tt
				OR = {
					is_independent_ruler = yes
					highest_held_title_tier < liege.highest_held_title_tier_minus_one
				}
			}
			NOT = {
				has_character_modifier = promised_pilgrimage_to_clergy_modifier
			}
			custom_tooltip = {
				text = valid_request_unformed_title_tt
				any_held_title = {
					de_jure_liege ?= {
						target_valid_request_unformed_title_trigger = yes
					}
				}
			}
		}
		scope:recipient = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
				adult = yes
			}
			NOT = {
				has_trait = excommunicated
			}
			piety_level >= 2
			highest_held_title_tier >= tier_duchy
			faith = scope:puppet_or_actor.faith
			trigger_if = {
				limit = {
					NOT = {
						scope:puppet_or_actor.religious_head_or_challenger ?= this
					}
				}
				rite = scope:puppet_or_actor.rite
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= pam_request_unformed_title_piety_cost_value
			}
		}
	}

	can_be_picked_title = {
		scope:target = {
			target_valid_request_unformed_title_trigger = yes
		}
	}

	has_valid_target_showing_failures_only = {
		exists = scope:target
		scope:target = {
			is_landless_type_title = no
			is_head_of_faith = no
			tier > tier_county
			tier >= scope:puppet_or_actor.highest_held_title_tier
			NOT = { exists = holder }
			any_direct_de_jure_vassal_title = {
				holder ?= scope:puppet_or_actor
			}
		}
	}

	cost = {
		piety = {
			value = pam_request_unformed_title_piety_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:puppet_or_actor
			object = scope:recipient
			scope:use_hook = yes
			scope:puppet_or_actor = { has_strong_hook = scope:recipient }
		}
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				if = {
					limit = { pam_request_unformed_title_piety_cost_value > 0 }
					add_piety = {
						value = {
							add = pam_request_unformed_title_piety_cost_value
							max = piety
							multiply = -1
						}
					}
				}
			}
		}
		scope:recipient = {
			save_scope_as = cleric
		}
		#Crowning a vassal over their liege's head is an affront to the liege
		if = {
			limit = {
				scope:puppet_or_actor = {
					is_independent_ruler = no
					liege = {
						NOT = {
							this = scope:recipient
						}
					}
				}
			}
			scope:puppet_or_actor.liege = {
				add_opinion = {
					target = scope:recipient
					modifier = circumvented_my_authority_opinion
					opinion = -25
				}
				add_opinion = {
					target = scope:puppet_or_actor
					modifier = circumvented_my_authority_opinion
					opinion = {
						value = -15
						if = {
							limit = {
								exists = scope:target
								scope:target.tier = scope:puppet_or_actor.liege.highest_held_title_tier_minus_one
							}
							add = -15
						}
					}
				}
			}
		}
		if = {
			limit = {
				scope:recipient = {
					is_ai = no
				}
			}
			scope:puppet_or_actor = {
				add_opinion = {
					target = scope:recipient
					modifier = grateful_opinion
					opinion = 30
				}
			}
		}
		else = {
			hidden_effect = {
				scope:puppet_or_actor = {
					add_opinion = {
						target = scope:recipient
						modifier = grateful_opinion
						opinion = 50
					}
				}
			}
		}
		scope:puppet_or_actor = {
			show_as_tooltip = { request_unformed_title_effect = yes }
			trigger_event = pam_interactions_events.0097
		}
	}

	on_decline = {
		if = {
			limit = {
				scope:recipient = {
					is_ai = no
				}
			}
			scope:puppet_or_actor = {
				add_opinion = {
					target = scope:recipient
					modifier = refusal_opinion
					opinion = -50
				}
			}
		}
		scope:puppet_or_actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = request_unformed_title_refusal_toast_tt
				left_icon = scope:recipient
			}
		}
		if = {
			limit = {
				scope:is_puppet_action ?= yes
				scope:actor != scope:recipient
			}
			scope:actor = {
				send_interface_toast = {
					type = event_toast_effect_bad
					title = request_unformed_title_refusal_toast_tt_puppeteer
					left_icon = scope:puppet_or_actor
					right_icon = scope:recipient
				}
			}
		}
	}

	send_options_exclusive = no
	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				has_usable_hook = scope:recipient
			}
			trigger_if = {
				limit = {
					scope:recipient = {
						is_ai = no
					}
				}
				scope:actor = { is_ai = no }
			}
		}
		flag = use_hook
		localization = EDUCATION_HOOK
	}
	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				short_term_gold >= major_gold_value
			}
		}
		flag = donate_faith
		localization = DONATE_TO_THE_FAITH_INTERACTION_OPTION
	}
	send_option = {
		is_valid = {
			NOT = {
				scope:recipient = {
					has_usable_hook = scope:puppet_or_actor
				}
			}
			scope:recipient = {
				can_add_hook = {
					target = scope:puppet_or_actor
					type = favor_hook
				}
			}
		}
		flag = offer_hook
		localization = OFFER_HOOK_INTERACTION_OPTION
	}
	#Swear to wrest the rest of the realm from the heathens holding it. Hidden below kingdom tier, since the free casus belli only covers kingdom-tier holy wars.
	send_option = {
		is_shown = {
			scope:target ?= {
				tier = tier_kingdom
			}
		}
		is_valid = {
			scope:puppet_or_actor = {
				faith = {
					NOT = { has_doctrine_parameter = unreformed }
				}
				#A personal vow of pacifism bars offensive war outright, and bonus_major_holy_war grants no exemption from it
				NOT = { has_personal_tenet_flag = tenet_pacifism_no_offensive_war }
			}
			custom_tooltip = {
				text = valid_request_unformed_title_holy_war_option_tt
				scope:target ?= {
					any_de_jure_county = {
						percent >= 0.25
						holder ?= {
							save_temporary_scope_as = heathen_holder
							rite = {
								is_hostile_enough_for_holy_war_trigger = { RITE = scope:puppet_or_actor.rite }
							}
							#A holder you cannot lawfully attack is no use as a war target, vassals and fellow subjects included
							scope:puppet_or_actor = {
								allows_declaring_war_against_target_trigger = { TARGET = scope:heathen_holder }
							}
						}
					}
				}
			}
		}
		flag = promise_holy_war
		localization = PROMISE_HOLY_WAR_INTERACTION_OPTION
	}

	send_option = {
		is_shown = {
			pam_offer_pilgrimage_option_shown_trigger = { ACTOR = scope:puppet_or_actor }
		}
		is_valid = {
			pam_offer_pilgrimage_option_valid_trigger = { ACTOR = scope:puppet_or_actor }
		}
		flag = offer_pilgrimage
		localization = OFFER_PILGRIMAGE_INTERACTION_OPTION
	}

	ai_accept = {
		base = -100

		modifier = {
			desc = pam_sf_ear_of_clergy_accept_reason
			scope:puppet_or_actor = { has_character_modifier = pam_sf_ear_of_clergy_modifier }
			add = 25
		}
		modifier = {
			desc = SCHEME_WEAK_HOOK_USED
			scope:use_hook = yes
			scope:puppet_or_actor = { NOT = { has_strong_hook = scope:recipient } }
			add = 200
		}
		modifier = {
			desc = OFFER_HOOK_INTERACTION_OPTION_REASON
			scope:offer_hook = yes
			add = {
				value = scope:puppet_or_actor.highest_held_title_tier
				multiply = 20
			}
		}
		modifier = {
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
			scope:donate_faith = yes
			add = 50
		}
		modifier = {
			desc = PROMISE_HOLY_WAR_INTERACTION_OPTION_REASON
			scope:promise_holy_war = yes
			add = 75
		}
		modifier = {
			add = pam_offer_pilgrimage_acceptance_value
			scope:offer_pilgrimage = yes
			desc = OFFER_PILGRIMAGE_INTERACTION_OPTION_REASON
		}

		general_secular_to_ecclesiastic_acceptance_modifier = yes

		#Asking to be raised above your own rank is the real favour; a crown costs more than a coronet
		modifier = {
			desc = request_unformed_title_tier_above_own_reason
			exists = scope:target
			scope:target = {
				tier >= tier_kingdom
				tier > scope:puppet_or_actor.highest_held_title_tier
			}
			add = {
				value = scope:target.tier
				subtract = 3
				multiply = -50
			}
		}
		#A ruler who already rules the land is simply asking for the crown that goes with it. These bands stack.
		modifier = {
			desc = request_unformed_title_partly_controls_target_reason
			exists = scope:target
			scope:target = {
				any_de_jure_county = {
					percent >= 0.33
					holder ?= {
						target_is_same_character_or_above = scope:puppet_or_actor
					}
				}
			}
			add = 40
		}
		modifier = {
			desc = request_unformed_title_mostly_controls_target_reason
			exists = scope:target
			scope:target = {
				any_de_jure_county = {
					percent >= 0.5
					holder ?= {
						target_is_same_character_or_above = scope:puppet_or_actor
					}
				}
			}
			add = 40
		}
		modifier = {
			desc = request_unformed_title_controls_target_reason
			exists = scope:target
			scope:target = {
				any_de_jure_county = {
					count = all
					holder ?= {
						target_is_same_character_or_above = scope:puppet_or_actor
					}
				}
			}
			add = 70
		}
		#The clergy will not crown a ruler over land that is not yet theirs in spirit
		modifier = {
			desc = request_unformed_title_faithless_de_jure_reason
			exists = scope:target
			scope:target = {
				NOT = {
					any_de_jure_county = {
						percent >= 0.75
						faith = scope:puppet_or_actor.faith
					}
				}
			}
			add = -50
		}
		modifier = {
			desc = LOW_LEGITIMACY_REASON
			scope:puppet_or_actor = {
				has_legitimacy = yes
				legitimacy_level <= 1
			}
			add = -150
		}
		modifier = {
			desc = LOW_LEGITIMACY_REASON
			scope:puppet_or_actor = {
				has_legitimacy = yes
				legitimacy_level = 2
			}
			add = -25
		}
		modifier = {
			desc = HIGH_LEGITIMACY_REASON
			scope:puppet_or_actor = {
				has_legitimacy = yes
				legitimacy_level >= 4
			}
			add = {
				value = scope:puppet_or_actor.legitimacy_level
				subtract = 3
				multiply = 50
			}
		}
	}

	ai_targets = {
		ai_recipients = head_of_faith
		ai_recipients = realm_priest_superior
		ai_recipients = realm_priest_top_superior
		max = 3
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 60
		kingdom = 90
		empire = 0
		hegemony = 0
	}

	ai_will_do = {
		base = 20
		modifier = {
			exists = scope:target
			scope:target = {
				any_de_jure_county = {
					count = all
					holder ?= {
						target_is_same_character_or_above = scope:puppet_or_actor
					}
				}
			}
			add = 50
		}
		modifier = {
			exists = scope:target
			scope:target = {
				any_de_jure_county = {
					percent >= 0.5
					holder ?= {
						target_is_same_character_or_above = scope:puppet_or_actor
					}
				}
			}
			add = 25
		}
		modifier = {
			OR = {
				ai_greed < 0
				ai_energy < 0
				trigger_if = {
					limit = {
						has_legitimacy = yes
					}
					legitimacy_level < 2
				}
			}
			factor = 0
		}
	}
}

pam_clergy_legitimize_bastard_interaction = {
	category = interaction_category_religion
	icon = legitimized_bastard
	use_diplomatic_range = no

	desc = pam_clergy_legitimize_bastard_interaction_desc

	is_available = {
		pam_is_clergy_ruler_trigger = yes
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:actor.rite ?= {
			rite_has_parameter = bastards_legitimize
		}
		scope:recipient = {
			this != scope:actor
			has_trait = bastard
			is_lowborn = no
			faith ?= scope:actor.faith
			rite ?= {
				rite_has_parameter = bastards_legitimize
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_available_adult = yes
			NOT = {
				has_trait = excommunicated
			}
		}
		#Range: the Head of Faith reaches anyone, archbishops their clerical region, and all theocrats their own top realm
		trigger_if = {
			limit = {
				scope:actor = {
					NOT = { religious_head_or_challenger ?= this }
					any_held_title = { has_clerical_region = yes }
				}
			}
			custom_tooltip = {
				text = pam_clergy_legitimize_bastard_archbishop_range_tt
				OR = {
					scope:recipient.top_liege ?= scope:actor.top_liege
					scope:recipient = {
						OR = {
							capital_county ?= {
								clerical_region_title ?= { holder = scope:actor }
							}
							location.county ?= {
								clerical_region_title ?= { holder = scope:actor }
							}
						}
					}
				}
			}
		}
		trigger_else_if = {
			limit = {
				scope:actor = {
					NOT = { religious_head_or_challenger ?= this }
				}
			}
			custom_tooltip = {
				text = pam_clergy_legitimize_bastard_realm_range_tt
				scope:recipient.top_liege ?= scope:actor.top_liege
			}
		}
		trigger_else = {
			always = yes
		}
	}

	cost = {
		piety = minor_piety_value
	}

	auto_accept = yes

	on_accept = {
		scope:actor = {
			send_interface_message = {
				type = event_religious_good
				title = pam_clergy_legitimize_bastard_interaction_notification
				right_icon = scope:recipient
				scope:recipient = {
					hidden_effect = {
						remove_trait = bastard
					}
					add_trait_force_tooltip = legitimized_bastard
					add_opinion = {
						target = scope:actor
						modifier = legitimized_me_opinion
						opinion = 35
					}
				}
				add_hook = {
					type = legitimized_by_clergy_hook
					target = scope:recipient
				}
			}
		}

		hidden_effect = {
			scope:recipient = {
				trigger_event = pam_interactions_events.0100
				every_parent = {
					limit = {
						this != scope:actor
					}
					if = { #Nudge towards friendship
						limit = {
							NOR = {
								has_relation_friend = scope:actor
								has_relation_potential_friend = scope:actor
							}
						}
						set_relation_potential_friend = scope:actor
					}
					trigger_event = pam_interactions_events.0101
				}
			}
			scope:actor = {
				if = {
					limit = {
						has_character_modifier = oath_of_children
						exists = scope:actor.house
						scope:recipient.house ?= scope:actor.house
					}
					remove_character_modifier = oath_of_children
					add_character_modifier = oath_of_children
				}
			}
		}
	}
}

#Secular rulers petition the clergy to recognize a neighboring title as de jure part of their primary realm
ecclesiastical_de_jure_shifting_interaction = {
	category = interaction_category_religion
	icon = ecclesiastical_de_jure_shifting_interaction

	interface_priority = 39
	common_interaction = yes
	target_type = title
	target_filter = dejure_titles
	target_source = actor
	show_all_targets = yes
	notification_text = ecclesiastical_de_jure_shifting_interaction_notification
	greeting = positive

	use_diplomatic_range = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes

	desc = ecclesiastical_de_jure_shifting_interaction_desc

	cooldown = { years = 3 }

	is_available = {
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			highest_held_title_tier >= tier_kingdom
			is_landed = yes
			pam_clergy_interactions_faith_trigger = yes
			is_ruler = yes
		}
		scope:puppet_or_actor ?= {
			NOR = {
				this = scope:recipient
				is_at_war_with = scope:recipient
			}
			any_sub_realm_title = {
				any_this_title_or_de_jure_above = {
					target_valid_ecclesiastical_de_jure_shifting_trigger = yes
				}
			}
		}
		scope:recipient = {
			pam_request_legitimacy_priest_trigger = { CHARACTER = scope:puppet_or_actor }
			NOT = { this = scope:actor }
		}
	}

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			is_at_war = no
			clergy_interaction_generic_piety_level_or_puppet_req_trigger = yes
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
			}
			is_landed = yes
			NOT = {
				has_trait = excommunicated
			}
			primary_title = {
				is_landless_type_title = no
			}
			custom_tooltip = {
				text = valid_ecclesiastical_de_jure_shifting_title_tt
				any_sub_realm_title = {
						any_this_title_or_de_jure_above = {
						target_valid_ecclesiastical_de_jure_shifting_trigger = yes
						any_de_jure_county = {
							percent >= 0.5
							faith = scope:puppet_or_actor.faith
						}
						any_de_jure_county = {
							percent >= 0.5
							holder = { faith = scope:puppet_or_actor.faith }
						}
					}
				}
			}
			NOT = {
				has_character_modifier = promised_pilgrimage_to_clergy_modifier
			}
		}
		scope:recipient = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
				adult = yes
			}
			NOT = {
				has_trait = excommunicated
			}
			highest_held_title_tier >= tier_duchy

			custom_tooltip = {
				text = relevant_theocrat_tt
				OR = {
					scope:puppet_or_actor.religious_head_or_challenger ?= scope:recipient
					scope:puppet_or_actor = {
						any_liege_or_above = {
							this = scope:recipient
						}
					}
					any_held_title = {
						has_clerical_region = yes
						any_county_in_clerical_region = {
							OR = {
								this = scope:puppet_or_actor.primary_title
								scope:puppet_or_actor.primary_title = {
									is_de_jure_liege_or_above_target = prev
								}
							}
						}
					}
					AND = {
						is_landed = yes
						any_held_title = {
							OR = {
								#they have a title beneath actor's titles
								any_this_title_or_de_jure_above = {
									holder ?= scope:puppet_or_actor
								}
								#they have a title that presides over actor's titles
								any_in_de_jure_hierarchy = {
									holder ?= scope:puppet_or_actor
								}
							}
						}
					}
				}
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= pam_ecclesiastical_de_jure_shifting_piety_cost_value
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				prestige >= pam_ecclesiastical_de_jure_shifting_prestige_cost_value
			}
		}
	}

	can_be_picked_title = {
		scope:target = {
			target_valid_ecclesiastical_de_jure_shifting_trigger = yes

			#At least half of its counties belong to your faith
			custom_tooltip = {
				text = half_target_de_jure_counties_belong_to_faith_tt
				any_de_jure_county = {
					percent >= 0.5
					faith = scope:puppet_or_actor.faith
				}
			}
			
			#At least half of its counties' rulers are of your faith
			custom_tooltip = {
				text = half_target_de_jure_holders_belong_to_faith_tt
				any_de_jure_county = {
					percent >= 0.5
					holder = { faith = scope:puppet_or_actor.faith }
				}
			}
		}
	}

	has_valid_target_showing_failures_only = {
		exists = scope:target
		scope:target = {
			is_landless_type_title = no
			is_head_of_faith = no
			tier = scope:puppet_or_actor.highest_held_title_tier_minus_one
			NOT = {
				de_jure_liege = scope:puppet_or_actor.primary_title
			}
			custom_tooltip = {
				text = petition_de_jure_integration_target_is_connected_tt
				any_de_jure_county = {
					holder ?= {
						target_is_same_character_or_above = scope:puppet_or_actor
					}
				}
			}
		}
	}

	cost = {
		piety = {
			value = pam_ecclesiastical_de_jure_shifting_piety_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
		prestige = {
			value = pam_ecclesiastical_de_jure_shifting_prestige_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:puppet_or_actor
			object = scope:recipient
			scope:use_hook = yes
			scope:puppet_or_actor = { has_strong_hook = scope:recipient }
		}
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				if = {
					limit = { pam_ecclesiastical_de_jure_shifting_piety_cost_value > 0 }
					add_piety = {
						value = {
							add = pam_ecclesiastical_de_jure_shifting_piety_cost_value
							max = piety
							multiply = -1
						}
					}
				}
				if = {
					limit = { pam_ecclesiastical_de_jure_shifting_prestige_cost_value > 0 }
					add_prestige = {
						value = {
							add = pam_ecclesiastical_de_jure_shifting_prestige_cost_value
							max = prestige
							multiply = -1
						}
					}
				}
			}
		}
		scope:target ?= {
			de_jure_liege = {
				save_scope_as = former_de_jure_liege
			}
		}
		scope:puppet_or_actor = {
			save_scope_as = de_jure_master
			faith = { save_scope_as = de_jure_faith }
		}
		scope:recipient = {
			save_scope_as = cleric
		}	
		if = {
			limit = {
				scope:target.de_jure_liege.holder?= {
					NOT = {
						this = scope:puppet_or_actor
					}
				}
			}
			scope:target.de_jure_liege.holder = {
				add_opinion = {
					target = scope:puppet_or_actor
					modifier = stole_de_jure_lands_opinion
					opinion = -70
				}
			}
			scope:recipient = {
				if = {
					limit = {
						is_ai = no
					}
					scope:target.de_jure_liege.holder = {
						add_opinion = {
							target = scope:puppet_or_actor
							modifier = gave_away_de_jure_lands_opinion
							opinion = -50
						}
					}
				}
				else = {
					hidden_effect = {
						scope:target.de_jure_liege.holder = {
							add_opinion = {
								target = scope:puppet_or_actor
								modifier = gave_away_de_jure_lands_opinion
								opinion = -50
							}
						}
					}
				}
			}
		}
		scope:recipient = {
			if = {
				limit = {
					is_ai = no
				}
				scope:puppet_or_actor = {
					add_opinion = {
						target = scope:recipient
						modifier = grateful_opinion
						opinion = 30
					}
				}
			}
			else = {
				hidden_effect = {
					scope:puppet_or_actor = {
						add_opinion = {
							target = scope:recipient
							modifier = grateful_opinion
							opinion = 50
						}
					}
				}
			}
			if = {
				limit = {
					is_ai = no
				}
				custom_tooltip = every_subordinate_in_target_de_jure_liege_opinion_loss
				custom_tooltip = every_subordinate_in_actor_title_opinion_gain
			}
			hidden_effect = {
				#Bishops based in different dioceses have feelings
				every_subordinate = {
					limit = {
						capital_province.county ?= {
							any_this_title_or_de_jure_above = {
								this = scope:former_de_jure_liege
							}
						}
						NOR = {
							this = scope:puppet_or_actor
							this = scope:recipient
						}
					}
					add_opinion = {
						target = scope:recipient
						modifier = ruled_against_my_diocese_opinion
						opinion = -25
					}
				}
				every_subordinate = {
					limit = {
						capital_province.county ?= {
							any_this_title_or_de_jure_above = {
								this = scope:puppet_or_actor.primary_title
							}
						}
						NOR = {
							this = scope:puppet_or_actor
							this = scope:recipient
						}
					}
					add_opinion = {
						target = scope:recipient
						modifier = ruled_in_favor_of_my_diocese_opinion
						opinion = 25
					}
				}
			}
		}
		scope:puppet_or_actor = {
			show_as_tooltip = {
				ecclesiastical_de_jure_shifting_effect = {
					DE_JURE_MASTER = scope:puppet_or_actor
					CLERIC = scope:recipient
				}
			}
			trigger_event = pam_interactions_events.0094
		}
	}

	on_decline = {
		scope:target ?= {
			de_jure_liege = {
				save_scope_as = former_de_jure_liege
			}
		}
		if = {
			limit = {
				scope:recipient = {
					is_ai = no
				}
			}
			scope:puppet_or_actor = {
				add_opinion = {
					modifier = refusal_opinion
					target = scope:recipient
					opinion = -50
				}
			}
			if = {
				limit = {
					scope:target.de_jure_liege.holder ?= {
						NOT = {
							this = scope:puppet_or_actor
						}
					}
				}
				scope:target.de_jure_liege.holder ?= {
					add_opinion = {
						modifier = respected_de_jure_opinion
						target = scope:recipient
						opinion = 50
					}
				}
			}

			scope:recipient = {
				if = {
					limit = {
						is_ai = no
					}
					custom_tooltip = every_subordinate_in_target_de_jure_liege_opinion_gain
					custom_tooltip = every_subordinate_in_actor_title_opinion_loss
				}
				hidden_effect = {
					#Bishops based in different dioceses have feelings
					every_subordinate = {
						limit = {
							capital_province.county ?= {
								any_this_title_or_de_jure_above = {
									this = scope:former_de_jure_liege
								}
							}
							NOR = {
								this = scope:puppet_or_actor
								this = scope:recipient
							}
						}
						add_opinion = {
							target = scope:recipient
							modifier = ruled_in_favor_of_my_diocese_opinion
							opinion = 25
						}
					}
					every_subordinate = {
						limit = {
							capital_province.county ?= {
								any_this_title_or_de_jure_above = {
									this = scope:puppet_or_actor.primary_title
								}
							}
							NOR = {
								this = scope:puppet_or_actor
								this = scope:recipient
							}
						}
						add_opinion = {
							target = scope:recipient
							modifier = ruled_against_my_diocese_opinion
							opinion = -25
						}
					}
				}
			}
		}
		
		scope:puppet_or_actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = ecclesiastic_de_jure_refusal_toast_tt
				left_icon = scope:recipient
			}
		}
		if = {
			limit = {
				scope:is_puppet_action ?= yes
				scope:actor != scope:recipient
			}
			scope:actor = {
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ecclesiastic_de_jure_refusal_toast_tt_puppeteer
					left_icon = scope:puppet_or_actor
					right_icon = scope:recipient
				}
			}
		}
	}

	send_options_exclusive = no
	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				has_usable_hook = scope:recipient
			}
			trigger_if = {
				limit = {
					scope:recipient = {
						is_ai = no
					}
				}
				scope:actor = { is_ai = no }
			}
		}
		flag = use_hook
		localization = EDUCATION_HOOK
	}
	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				short_term_gold >= major_gold_value
			}
		}
		flag = donate_faith
		localization = DONATE_TO_THE_FAITH_INTERACTION_OPTION
	}
	send_option = {
		is_valid = {
			NOT = {
				scope:recipient = {
					has_usable_hook = scope:puppet_or_actor
				}
			}
			scope:recipient = {
				can_add_hook = {
					target = scope:puppet_or_actor
					type = favor_hook
				}
			}
		}
		flag = offer_hook
		localization = OFFER_HOOK_INTERACTION_OPTION
	}
	#Promise to convert every ruler of the region
	send_option = {
		is_valid = {
			custom_tooltip = {
				text = valid_domination_interaction_option_tt
				scope:target ?= {
					any_de_jure_county = {
						holder ?= {
							OR = {
								faith = {
									NOT = {
										this = scope:puppet_or_actor.faith
									}
								}
								any_liege_or_above = {
									faith = {
										NOT = {
											this = scope:puppet_or_actor.faith
										}
									}
									NOT = {
										is_liege_or_above_of = scope:puppet_or_actor
									}
								}
							}
						}
					}
				}
			}
		}
		flag = promise_domination
		localization = PROMISE_DOMINATION_INTERACTION_OPTION
	}
	#Deploy missionaries throughout the kingdom
	send_option = {
		is_valid = {
			custom_tooltip = {
				text = valid_conversion_interaction_option_tt
				scope:target ?= {
					any_de_jure_county = {
						OR = {
							NOT = {
								faith = scope:puppet_or_actor.faith
							}
							trigger_if = {
								limit = {
									scope:puppet_or_actor.rite = scope:recipient.rite
								}
								AND = {
									NOT = {
										rite = scope:puppet_or_actor.rite
									}
									rite = {
										"divergence(scope:puppet_or_actor.rite)" >= medium_rite_divergence_value
									}
								}
							}
						}
					}
				}
			}
		}
		flag = promise_conversion
		localization = PROMISE_CONVERSION_INTERACTION_OPTION
	}
	send_option = {
		is_shown = {
			pam_offer_pilgrimage_option_shown_trigger = { ACTOR = scope:puppet_or_actor }
		}
		is_valid = {
			pam_offer_pilgrimage_option_valid_trigger = { ACTOR = scope:puppet_or_actor }
		}
		flag = offer_pilgrimage
		localization = OFFER_PILGRIMAGE_INTERACTION_OPTION
	}

	ai_accept = {
		base = -150

		modifier = {
			scope:puppet_or_actor = { has_character_modifier = pam_sf_ear_of_clergy_modifier }
			add = 25
			desc = pam_sf_ear_of_clergy_accept_reason
		}
		modifier = { # Peace of God: redrawing de jure borders by decree spares a war of conquest
			scope:recipient.rite ?= {
				rite_has_parameter = tenet_peace_of_god_clergy_peacemaking
			}
			add = 50
			desc = pam_peace_of_god_clergy_peacemaking_accept_reason
		}
		modifier = {
			scope:use_hook = yes
			add = 200
			scope:puppet_or_actor = { NOT = { has_strong_hook = scope:recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			add = {
				value = 20
				multiply = scope:puppet_or_actor.highest_held_title_tier
			}
			scope:offer_hook = yes
			desc = OFFER_HOOK_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 50
				if = {
					limit = {
						pam_actor_rite_has_core_simony_trigger = yes
					}
					multiply = 5
				}
			}
			scope:donate_faith = yes
			desc = DONATE_FAITH_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = pam_offer_pilgrimage_acceptance_value
			scope:offer_pilgrimage = yes
			desc = OFFER_PILGRIMAGE_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 0
				scope:target ?= {
					every_de_jure_county = {
						limit = {
							holder ?= {
								OR = {
									faith = {
										NOT = {
											this = scope:puppet_or_actor.faith
										}
									}
									any_liege_or_above = {
										faith = {
											NOT = {
												this = scope:puppet_or_actor.faith
											}
										}
									}
								}
							}
						}
						add = 1
						if = {
							limit = {
								holder.rite = {
									NOT = {
										this = scope:puppet_or_actor.rite
									}
									rite_hostility_level = {
										target = scope:puppet_or_actor.rite
										value >= faith_astray_level
									}
								}
							}
							add = 1
						}
						if = {
							limit = {
								holder.rite = {
									NOT = {
										this = scope:puppet_or_actor.rite
									}
									rite_hostility_level = {
										target = scope:puppet_or_actor.rite
										value >= faith_hostile_level
									}
								}
							}
							add = 3
						}
						if = {
							limit = {
								holder.rite = {
									NOT = {
										this = scope:puppet_or_actor.rite
									}
									rite_hostility_level = {
										target = scope:puppet_or_actor.rite
										value >= faith_evil_level
									}
								}
							}
							add = 2
						}
						add = {
							value = holder.highest_held_title_tier
							subtract = 1
						}
					}
				}
				
				if = {
					limit = {
						scope:target.tier = tier_kingdom
					}
					multiply = 2
				}
				if = {
					limit = {
						scope:target.tier = tier_duchy
					}
					multiply = 4
				}
				multiply = 2
			}
			scope:promise_domination = yes
			desc = PROMISE_DOMINATION_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = {
				value = 0
				scope:target ?= {
					every_de_jure_county = {
						limit = {
							OR = {
								NOT = {
									faith = scope:puppet_or_actor.faith
								}
								trigger_if = {
									limit = {
										scope:puppet_or_actor.rite = scope:recipient.rite
									}
									AND = {
										NOT = {
											rite = scope:puppet_or_actor.rite
										}
										rite = {
											"divergence(scope:puppet_or_actor.rite)" >= medium_rite_divergence_value
										}
									}
								}
							}
						}
						add = 1
						if = {
							limit = {
								rite = {
									"divergence(scope:puppet_or_actor.rite)" >= major_rite_divergence_value
								}
							}
							add = 1
						}
						if = {
							limit = {
								rite = {
									"divergence(scope:puppet_or_actor.rite)" >= monumental_rite_divergence_value
								}
							}
							add = 1
						}
						if = {
							limit = {
								rite = {
									NOT = {
										this = scope:puppet_or_actor.rite
									}
									rite_hostility_level = {
										target = scope:puppet_or_actor.rite
										value >= faith_astray_level
									}
								}
							}
							add = 1
						}
						if = {
							limit = {
								rite = {
									NOT = {
										this = scope:puppet_or_actor.rite
									}
									rite_hostility_level = {
										target = scope:puppet_or_actor.rite
										value >= faith_hostile_level
									}
								}
							}
							add = 2
						}
						if = {
							limit = {
								rite = {
									NOT = {
										this = scope:puppet_or_actor.rite
									}
									rite_hostility_level = {
										target = scope:puppet_or_actor.rite
										value >= faith_evil_level
									}
								}
							}
							add = 2
						}
					}
				}
				
				if = {
					limit = {
						scope:target.tier = tier_kingdom
					}
					multiply = 2
				}
				if = {
					limit = {
						scope:target.tier = tier_duchy
					}
					multiply = 4
				}
			}
			exists = scope:target
			scope:promise_conversion = yes
			desc = PROMISE_CONVERSION_INTERACTION_OPTION_REASON
		}
		#From other rite rulers
		modifier = {
			add = {
				value = 0
				scope:target ?= {
					every_de_jure_county = {
						limit = {
							holder ?= {
								NOT = {
									is_vassal_or_below_of = scope:puppet_or_actor
								}
								OR = {
									faith = {
										NOT = {
											this = scope:puppet_or_actor.faith
										}
									}
									any_liege_or_above = {
										faith = {
											NOT = {
												this = scope:puppet_or_actor.faith
											}
										}
										NOT = {
											is_liege_or_above_of = scope:puppet_or_actor
										}
									}
								}
							}
						}
						add = 1
						if = {
							limit = {
								holder.rite = {
									"divergence(scope:puppet_or_actor.rite)" >= major_rite_divergence_value
								}
							}
							add = 1
						}
						if = {
							limit = {
								holder.rite = {
									"divergence(scope:puppet_or_actor.rite)" >= monumental_rite_divergence_value
								}
							}
							add = 1
						}
						add = {
							value = holder.highest_held_title_tier
							subtract = 1
						}
					}
				}
				
				if = {
					limit = {
						scope:target.tier = tier_kingdom
					}
					multiply = 2
				}
				if = {
					limit = {
						scope:target.tier = tier_duchy
					}
					multiply = 4
				}
			}
			scope:puppet_or_actor.rite = scope:recipient.rite
			scope:target ?= {
				any_de_jure_county = {
					holder = {
						NOT = {
							is_vassal_or_below_of = scope:puppet_or_actor
						}
						faith = scope:puppet_or_actor.faith
						OR = {
							rite = {
								NOT = {
									this = scope:puppet_or_actor.rite
								}
								"divergence(scope:puppet_or_actor.rite)" >= medium_rite_divergence_value
							}
							any_liege_or_above = {
								rite = {
									NOT = {
										this = scope:puppet_or_actor.rite
									}
									"divergence(scope:puppet_or_actor.rite)" >= medium_rite_divergence_value
								}
								NOT = {
									is_liege_or_above_of = scope:puppet_or_actor
								}
							}
						}
					}
				}
			}
			desc = OTHER_RITE_RULERS_REASON
		}
		#From other faith rulers
		modifier = {
			add = {
				value = 0
				scope:target ?= {
					every_de_jure_county = {
						limit = {
							holder ?= {
								NOT = {
									is_vassal_or_below_of = scope:puppet_or_actor
								}
								OR = {
									faith = {
										NOT = {
											this = scope:puppet_or_actor.faith
										}
									}
									any_liege_or_above = {
										faith = {
											NOT = {
												this = scope:puppet_or_actor.faith
											}
										}
										NOT = {
											is_liege_or_above_of = scope:puppet_or_actor
										}
									}
								}
							}
						}
						add = 1
						if = {
							limit = {
								holder.rite = {
									NOT = {
										this = scope:puppet_or_actor.rite
									}
									rite_hostility_level = {
										target = scope:puppet_or_actor.rite
										value >= faith_astray_level
									}
								}
							}
							add = 1
						}
						if = {
							limit = {
								holder.rite = {
									NOT = {
										this = scope:puppet_or_actor.rite
									}
									rite_hostility_level = {
										target = scope:puppet_or_actor.rite
										value >= faith_hostile_level
									}
								}
							}
							add = 2
						}
						if = {
							limit = {
								holder.rite = {
									NOT = {
										this = scope:puppet_or_actor.rite
									}
									rite_hostility_level = {
										target = scope:puppet_or_actor.rite
										value >= faith_evil_level
									}
								}
							}
							add = 2
						}
						add = {
							value = holder.highest_held_title_tier
							subtract = 1
						}
					}
				}
				
				if = {
					limit = {
						scope:target.tier = tier_kingdom
					}
					multiply = 2
				}
				if = {
					limit = {
						scope:target.tier = tier_duchy
					}
					multiply = 4
				}
			}
			scope:target ?= {
				any_de_jure_county = {
					holder ?= {
						NOT = {
							is_vassal_or_below_of = scope:puppet_or_actor
						}
						OR = {
							faith = {
								NOT = {
									this = scope:puppet_or_actor.faith
								}
							}
							any_liege_or_above = {
								faith = {
									NOT = {
										this = scope:puppet_or_actor.faith
									}
								}
								NOT = {
									is_liege_or_above_of = scope:puppet_or_actor
								}
							}
						}
					}
				}
			}
			desc = OTHER_FAITH_RULERS_REASON
		}
		#From other rite counties
		modifier = {
			add = {
				value = 0
				scope:target ?= {
					every_de_jure_county = {
						limit = {
							NOT = {
								rite = scope:puppet_or_actor.rite
							}
							rite = {
								"divergence(scope:puppet_or_actor.rite)" >= medium_rite_divergence_value
							}
						}
						add = 1
						if = {
							limit = {
								rite = {
									"divergence(scope:puppet_or_actor.rite)" >= major_rite_divergence_value
								}
							}
							add = 1
						}
						if = {
							limit = {
								rite = {
									"divergence(scope:puppet_or_actor.rite)" >= monumental_rite_divergence_value
								}
							}
							add = 1
						}
					}
				}
				
				if = {
					limit = {
						scope:target.tier = tier_kingdom
					}
					multiply = 2
				}
				if = {
					limit = {
						scope:target.tier = tier_duchy
					}
					multiply = 4
				}
			}
			scope:puppet_or_actor.rite = scope:recipient.rite
			scope:target ?= {
				any_de_jure_county = {
					faith = scope:puppet_or_actor.faith
					NOT = {
						rite = scope:puppet_or_actor.rite
					}
					rite = {
						"divergence(scope:puppet_or_actor.rite)" >= medium_rite_divergence_value
					}
				}
			}
			desc = OTHER_RITE_COUNTIES_REASON
		}
		#From other faith counties
		modifier = {
			add = {
				value = 0
				scope:target ?= {
					every_de_jure_county = {
						limit = {
							NOT = {
								faith = scope:puppet_or_actor.faith
							}
						}
						add = 1
						if = {
							limit = {
								rite = {
									NOT = {
										this = scope:puppet_or_actor.rite
									}
									rite_hostility_level = {
										target = scope:puppet_or_actor.rite
										value >= faith_astray_level
									}
								}
							}
							add = 1
						}
						if = {
							limit = {
								rite = {
									NOT = {
										this = scope:puppet_or_actor.rite
									}
									rite_hostility_level = {
										target = scope:puppet_or_actor.rite
										value >= faith_hostile_level
									}
								}
							}
							add = 2
						}
						if = {
							limit = {
								rite = {
									NOT = {
										this = scope:puppet_or_actor.rite
									}
									rite_hostility_level = {
										target = scope:puppet_or_actor.rite
										value >= faith_evil_level
									}
								}
							}
							add = 2
						}
					}
				}
				multiply = 2
				
				if = {
					limit = {
						scope:target.tier = tier_kingdom
					}
					multiply = 2
				}
				if = {
					limit = {
						scope:target.tier = tier_duchy
					}
					multiply = 4
				}
			}
			scope:target ?= {
				any_de_jure_county = {
					NOT = {
						faith = scope:puppet_or_actor.faith
					}
				}
			}
			desc = OTHER_FAITH_COUNTIES_REASON
		}
		modifier = {
			scope:target = {
				de_jure_liege ?= {
					holder ?= {
						NOR = {
							this = scope:puppet_or_actor
							this = scope:recipient
						}
						faith = scope:recipient.faith
					}
				}
			}
			add = -40
			desc = petition_de_jure_integration_displaces_faithful_ruler_reason
		}
		modifier = {
			scope:target = {
				de_jure_liege ?= {
					holder ?= {
						NOR = {
							this = scope:puppet_or_actor
							this = scope:recipient
						}
						num_sinful_traits > 0
					}
				}
			}
			add = {
				value = scope:target.de_jure_liege.holder.num_sinful_traits
				multiply = 10
			}
			desc = petition_de_jure_integration_sinful_de_jure_liege_reason
		}
		modifier = {
			scope:target = {
				any_de_jure_county = {
					count = all
					holder ?= {
						OR = {
							this = scope:puppet_or_actor
							any_liege_or_above = {
								this = scope:puppet_or_actor
							}
						}
					}
				}
			}
			add = 50
			desc = petition_de_jure_integration_controls_target_reason
		}

		general_secular_to_ecclesiastic_acceptance_modifier = yes
		modifier = {
			exists = scope:target
			scope:target.tier >= tier_kingdom
			add = {
				value = scope:target.tier
				subtract = 3
				multiply = -100
			}
			desc = TARGET_TIER_REASON
		}

		opinion_modifier = {
			opinion_target = scope:puppet_or_actor
			who = scope:recipient
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}

		#COUNTY FACTORS
		#Percentage of counties controlled
		modifier = {
			desc = counties_within_title_you_dont_control
			NOT = {
				scope:puppet_or_actor = {
					completely_controls = scope:target
				}
			}
			add = {
				value = 0
				scope:target ?= {
					every_de_jure_county = {
						limit = {
							NOT = {
								holder = {
									target_is_same_character_or_above = scope:puppet_or_actor
								}
							}
						}
						add = -2
						if = {
							limit = {
								holder = {
									OR = {
										AND = {
											NOT = { faith = scope:recipient.faith }
											rite = {
												rite_hostility_level = {
													target = scope:recipient.rite
													value <= faith_astray_level
												}
											}
										}
										AND = {
											faith = scope:recipient.faith
											NOT = {
												rite = scope:recipient.rite
											}
											rite = {
												"divergence(scope:recipient.rite)" >= medium_rite_divergence_value
											}
										}
									}
								}
							}
							add = -3
						}
						if = {
							limit = {
								holder = {
									faith = scope:recipient.faith
									rite = {
										"divergence(scope:recipient.rite)" < medium_rite_divergence_value
									}
								}
							}
							add = -5
						}
					}
				}
				if = {
					limit = {
						scope:target.tier = tier_kingdom
					}
					multiply = 2
				}
				if = {
					limit = {
						scope:target.tier = tier_duchy
					}
					multiply = 4
				}
			}
		}
		#Number of directly bordering counties with current de jure
		modifier = {
			desc = bordering_de_jure_counties_reason
			scope:target ?= {
				any_de_jure_county = {
					any_neighboring_county = {
						any_this_title_or_de_jure_above = {
							this = scope:puppet_or_actor.primary_title
						}
					}
				}
			}
			add = {
				value = 0
				scope:target ?= {
					every_de_jure_county = {
						limit = {
							any_neighboring_county = {
								any_this_title_or_de_jure_above = {
									this = scope:puppet_or_actor.primary_title
								}
							}
						}
						every_neighboring_county = {
							limit = {
								any_this_title_or_de_jure_above = {
									this = scope:puppet_or_actor.primary_title
								}
							}
							add = 3
						}
					}
				}
				if = {
					limit = {
						scope:target.tier = tier_kingdom
					}
					multiply = 2
				}
				if = {
					limit = {
						scope:target.tier = tier_duchy
					}
					multiply = 4
				}
			}
		}
		#Has distinct identity
		modifier = {
			desc = distinct_culture_counties_reason
			add = {
				value = 0
				scope:target = {
					every_de_jure_county = {
						limit = {
							NOT = {
								culture = scope:puppet_or_actor.culture
							}
						}
						add = -1
						if = {
							limit = {
								culture = {
									cultural_acceptance = {
										target = scope:puppet_or_actor.culture
										value < 40
									}
								}
							}
							add = -1
						}
						if = {
							limit = {
								culture = {
									cultural_acceptance = {
										target = scope:puppet_or_actor.culture
										value < 20
									}
								}
							}
							add = -1
						}
						if = {
							limit = {
								NOT = {
									culture = {
										has_same_culture_heritage = scope:puppet_or_actor.culture
									}
								}
							}
							add = -1
						}
						if = {
							limit = {
								NOT = {
									culture = {
										has_same_culture_language = scope:puppet_or_actor.culture
									}
								}
							}
							add = -1
						}
						if = {
							limit = {
								culture = scope:recipient.culture
							}
							add = -3
						}
						if = {
							limit = {
								NOT = {
									culture = scope:recipient.culture
								}
								culture = {
									has_same_culture_heritage = scope:recipient.culture
								}
							}
							add = -2
						}
						if = {
							limit = {
								NOT = {
									culture = scope:recipient.culture
								}
								culture = {
									has_same_culture_language = scope:recipient.culture
								}
							}
							add = -1
						}
					}
					if = {
						limit = {
							scope:target.tier = tier_kingdom
						}
						multiply = 2
					}
					if = {
						limit = {
							scope:target.tier = tier_duchy
						}
						multiply = 2
					}
					max = -1
				}
			}
			NOT = {
				scope:recipient.culture = scope:puppet_or_actor.culture
			}
			scope:target ?= {
				any_de_jure_county = {
					NOT = {
						culture = scope:puppet_or_actor.culture
					}
				}
			}
			OR = {
				#Kingdoms tend to be cultural, empires no
				scope:target.tier = tier_duchy
				#Recipient will try to defend own culture regardless
				scope:target ?= {
					any_de_jure_county = {
						culture = scope:recipient.culture
					}
				}
			}
		}
		#Your counties within target that have low control
		modifier = {
			desc = low_control_counties_in_target_reason
			scope:target ?= {
				any_de_jure_county = {
					holder = {
						target_is_same_character_or_above = scope:puppet_or_actor
					}
					county_control < 100
				}
			}
			add = {
				value = 0
				scope:target ?= {
					every_de_jure_county = {
						limit = {
							holder = {
								target_is_same_character_or_above = scope:puppet_or_actor
							}
							county_control < 100
						}
						add = -1
						if = {
							limit = {
								county_control < 75
							}
							add = -1
						}
						if = {
							limit = {
								county_control < 50
							}
							add = -1
						}
						if = {
							limit = {
								county_control < 25
							}
							add = -1
						}
					}
				}
				if = {
					limit = {
						scope:target.tier = tier_kingdom
					}
					multiply = 2
				}
				if = {
					limit = {
						scope:target.tier = tier_duchy
					}
					multiply = 4
				}
			}
		}
		#Legitimacy
		modifier = {
			scope:puppet_or_actor = {
				has_legitimacy = yes
				legitimacy_level = 0
			}
			add = -150
			desc = LOW_LEGITIMACY_REASON
		}
		modifier = {
			scope:puppet_or_actor = {
				has_legitimacy = yes
				legitimacy_level = 1
			}
			add = -100
			desc = LOW_LEGITIMACY_REASON
		}
		modifier = {
			scope:puppet_or_actor = {
				has_legitimacy = yes
				legitimacy_level = 2
			}
			add = -50
			desc = LOW_LEGITIMACY_REASON
		}
		modifier = {
			scope:puppet_or_actor = {
				has_legitimacy = yes
				legitimacy_level = 4
			}
			add = 25
			desc = HIGH_LEGITIMACY_REASON
		}
		modifier = {
			scope:puppet_or_actor = {
				has_legitimacy = yes
				legitimacy_level = 5
			}
			add = 100
			desc = HIGH_LEGITIMACY_REASON
		}
		modifier = {
			scope:puppet_or_actor = {
				has_legitimacy = yes
				legitimacy_level = 6
			}
			add = 150
			desc = HIGH_LEGITIMACY_REASON
		}
		modifier = {
			scope:puppet_or_actor = {
				has_legitimacy = yes
				legitimacy_level >= 7
			}
			add = 250
			desc = HIGH_LEGITIMACY_REASON
		}
	}

	ai_targets = {
		ai_recipients = head_of_faith
		ai_recipients = realm_priest_superior
		ai_recipients = realm_priest_top_superior
		max = 3
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 60
		empire = 60
		hegemony = 60
	}

	ai_will_do = {
		base = 10
		modifier = {
			exists = scope:target
			scope:target = {
				any_de_jure_county = {
					count = all
					holder ?= {
						OR = {
							this = scope:puppet_or_actor
							any_liege_or_above = {
								this = scope:puppet_or_actor
							}
						}
					}
				}
			}
			add = 50
		}
		modifier = {
			exists = scope:target
			scope:target = {
				any_de_jure_county = {
					percent >= 0.5
					holder ?= {
						OR = {
							this = scope:puppet_or_actor
							any_liege_or_above = {
								this = scope:puppet_or_actor
							}
						}
					}
				}
			}
			add = 50
		}
		modifier = {
			OR = {
				ai_greed < 0
				ai_energy < 0
				AND = {
					scope:target.de_jure_liege.holder ?= {
						NOR = {
							this = scope:puppet_or_actor
							this = scope:recipient
						}
					}
					has_any_good_relationship_with_character_trigger = { CHARACTER = scope:target.de_jure_liege.holder }
				}
				trigger_if = {
					limit = {
						has_legitimacy = yes
					}
					legitimacy_level < 2
				}
			}
			factor = 0
		}
	}
}

# Ecclesiastical rulers grant de jure recognition to a same-faith ruler
ecclesiastical_de_jure_shifting_grant_interaction = {
	category = interaction_category_religion
	icon = ecclesiastical_de_jure_shifting_interaction

	interface_priority = 39
	common_interaction = yes
	target_type = title
	target_filter = dejure_titles
	target_source = recipient
	show_all_targets = yes
	notification_text = ecclesiastical_de_jure_shifting_grant_interaction_notification
	greeting = positive
	cooldown_against_recipient = { years = 10 }

	use_diplomatic_range = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 5
	popup_on_receive = yes

	desc = ecclesiastical_de_jure_shifting_grant_interaction_desc

	is_available = {
		has_pam_dlc_trigger = yes
	}

	cost = {
		piety = {
			value = {
				add = pam_ecclesiastical_de_jure_shifting_piety_cost_value
				multiply = 0.5
			}
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
		prestige = {
			value = {
				add = pam_ecclesiastical_de_jure_shifting_prestige_cost_value
				multiply = 0.5
			}
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			government_has_flag = government_is_theocracy
			is_available_quick = {
				adult = yes
				alive = yes
				imprisoned = no
				incapable = no
			}
			this != scope:recipient
		}
		exists = scope:puppet_or_actor
		scope:puppet_or_actor ?= {
			OR = {
				scope:recipient.religious_head_or_challenger ?= this
				AND = {
					highest_held_title_tier >= tier_duchy
					government_has_flag = government_is_theocracy
					NOT = { exists = scope:recipient.religious_head_or_challenger }
					scope:recipient.rite.head_of_rite ?= this
				}
			}
		}
		scope:recipient = {
			is_landed = yes
			highest_held_title_tier >= tier_kingdom
			faith ?= scope:puppet_or_actor.faith
			any_held_title = {
				de_jure_liege ?= {
					tier < tier_hegemony
					NOT = { exists = holder }
					is_landless_type_title = no
				}
			}
			any_sub_realm_title = {
				any_this_title_or_de_jure_above = {
					is_landless_type_title = no
					is_head_of_faith = no
					tier = scope:recipient.highest_held_title_tier_minus_one
					NOT = {
						de_jure_liege = scope:recipient.primary_title
					}
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
				adult = yes
			}
			NOT = {
				has_trait = excommunicated
			}
		}
		scope:recipient = {
			is_available_quick = {
				incapable = no
				imprisoned = no
				hostage = no
				ruler = yes
				adult = yes
			}
			is_at_war = no
			NOT = {
				has_trait = excommunicated
			}
			primary_title = {
				is_landless_type_title = no
			}
			custom_tooltip = {
				text = valid_ecclesiastical_de_jure_shifting_grant_title_tt
				any_sub_realm_title = {
					any_this_title_or_de_jure_above = {
						is_landless_type_title = no
						is_head_of_faith = no
						tier = scope:recipient.highest_held_title_tier_minus_one
						NOT = {
							de_jure_liege = scope:recipient.primary_title
						}
						any_de_jure_county = {
							percent >= 0.5
							faith = scope:recipient.faith
						}
						any_de_jure_county = {
							percent >= 0.5
							holder = { faith = scope:recipient.faith }
						}
					}
				}
			}
		}
		trigger_if = {
			limit = {
				NOT = { scope:puppet_or_actor.religious_head_or_challenger ?= scope:puppet_or_actor }
			}
			scope:recipient.rite = scope:puppet_or_actor.rite
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= pam_ecclesiastical_de_jure_shifting_piety_cost_value
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				prestige >= pam_ecclesiastical_de_jure_shifting_prestige_cost_value
			}
		}
	}

	can_be_picked_title = {
		scope:target = {
			is_landless_type_title = no
			is_head_of_faith = no
			tier = scope:recipient.highest_held_title_tier_minus_one
			custom_tooltip = {
				text = ecclesiastical_de_jure_shifting_grant_not_already_de_jure_tt
				NOT = {
					de_jure_liege = scope:recipient.primary_title
				}
			}
			custom_tooltip = {
				text = recipient_holds_target_de_jure_county_tt
				any_de_jure_county = {
					holder ?= {
						target_is_same_character_or_above = scope:recipient
					}
				}
			}
			trigger_if = {
				limit = {
					exists = scope:puppet_or_actor.religious_head_or_challenger
					NOT = {
						scope:puppet_or_actor.religious_head_or_challenger = scope:puppet_or_actor
					}
					exists = scope:target.de_jure_liege.holder
				}
				custom_tooltip = {
					text = hof_is_target_de_jure_liege_tt
					NOT = {
						scope:puppet_or_actor.religious_head_or_challenger ?= scope:target.de_jure_liege.holder
					}
				}
			}
			trigger_if = {
				limit = {
					scope:actor = {
						is_ai = no
					}
				}
				custom_tooltip = {
					text = ecclesiastical_de_jure_shifting_grant_target_must_border_de_jure_tt
					any_de_jure_county = {
						any_title_to_title_neighboring_and_across_water_county = {
							any_this_title_or_de_jure_above = {
								this = scope:recipient.primary_title
							}
						}
					}
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = ecclesiastical_de_jure_shifting_grant_target_must_border_de_jure_land_tt
					any_de_jure_county = {
						any_title_to_title_neighboring_county = {
							any_this_title_or_de_jure_above = {
								this = scope:recipient.primary_title
							}
						}
					}
				}
			}

			# At least half of its counties belong to the beneficiary's faith
			custom_tooltip = {
				text = half_target_de_jure_counties_belong_to_faith_tt
				any_de_jure_county = {
					percent >= 0.5
					faith = scope:recipient.faith
				}
			}

			# At least half of its counties' rulers are of the beneficiary's faith
			custom_tooltip = {
				text = half_target_de_jure_holders_belong_to_faith_tt
				any_de_jure_county = {
					percent >= 0.5
					holder = { faith = scope:recipient.faith }
				}
			}
		}
	}

	has_valid_target_showing_failures_only = {
		exists = scope:target
		scope:target = {
			is_landless_type_title = no
			is_head_of_faith = no
			tier = scope:recipient.highest_held_title_tier_minus_one
			NOT = {
				de_jure_liege = scope:recipient.primary_title
			}
			custom_tooltip = {
				text = recipient_holds_target_de_jure_county_tt
				any_de_jure_county = {
					holder ?= {
						target_is_same_character_or_above = scope:recipient
					}
				}
			}
		}
	}

	auto_accept = {
		custom_tooltip = {
			text = no_reason_to_refuse_tt
			OR = {
				scope:recipient = { is_ai = yes }
				scope:recipient = scope:puppet_or_actor
			}
		}
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				if = {
					limit = { pam_ecclesiastical_de_jure_shifting_piety_cost_value > 0 }
					add_piety = {
						value = {
							add = pam_ecclesiastical_de_jure_shifting_piety_cost_value
							max = piety
							multiply = -1
						}
					}
				}
				if = {
					limit = { pam_ecclesiastical_de_jure_shifting_prestige_cost_value > 0 }
					add_prestige = {
						value = {
							add = pam_ecclesiastical_de_jure_shifting_prestige_cost_value
							max = prestige
							multiply = -1
						}
					}
				}
			}
		}
		# The existing effect/event expects puppet_or_actor to be the beneficiary and recipient to be the clerical authority.
		scope:recipient = {
			save_scope_as = de_jure_master
		}
		scope:puppet_or_actor = {
			save_scope_as = cleric
		}
		scope:target ?= {
			de_jure_liege = {
				save_scope_as = former_de_jure_liege
			}
		}
		scope:puppet_or_actor = {
			faith = { save_scope_as = de_jure_faith }
		}
		if = {
			limit = {
				scope:target.de_jure_liege.holder ?= {
					NOR = {
						this = scope:puppet_or_actor
						this = scope:recipient
					}
				}
			}
			scope:target.de_jure_liege.holder = {
				if = {
					limit = {
						scope:actor = {
							is_ai = no
						}
					}
					add_opinion = {
						target = scope:puppet_or_actor
						modifier = gave_away_de_jure_lands_opinion
						opinion = -70
					}
				}
				else = {
					hidden_effect = {
						add_opinion = {
							target = scope:puppet_or_actor
							modifier = gave_away_de_jure_lands_opinion
							opinion = -70
						}
					}
				}
			}
			if = {
				limit = {
					NOT = {
						scope:recipient = scope:puppet_or_actor
					}
				}
				scope:recipient = {
					if = {
						limit = {
							is_ai = no
						}
						scope:target.de_jure_liege.holder = {
							add_opinion = {
								target = scope:recipient
								modifier = stole_de_jure_lands_opinion
								opinion = -50
							}
						}
					}
					else = {
						hidden_effect = {
							scope:target.de_jure_liege.holder = {
								add_opinion = {
									target = scope:recipient
									modifier = stole_de_jure_lands_opinion
									opinion = -50
								}
							}
						}
					}
				}
			}
		}
		
		scope:recipient = {
			if = {
				limit = {
					NOT = {
						this = scope:puppet_or_actor
					}
				}
				if = {
					limit = {
						scope:actor = { is_ai = no }
					}
					add_opinion = {
						target = scope:puppet_or_actor
						modifier = grateful_opinion
						opinion = 30
					}
				}
				else = {
					hidden_effect = {
						scope:recipient = {
							add_opinion = {
								target = scope:puppet_or_actor
								modifier = grateful_opinion
								opinion = 30
							}
						}
					}
				}
			}
		}
		scope:puppet_or_actor = {
			if = {
				limit = {
					scope:actor = { is_ai = no }
				}
				custom_tooltip = every_subordinate_in_target_de_jure_liege_opinion_loss
				custom_tooltip = every_subordinate_in_actor_title_opinion_gain
			}
			hidden_effect = {
				# Bishops based in different dioceses have feelings
				every_subordinate = {
					limit = {
						capital_province.county ?= {
							any_this_title_or_de_jure_above = {
								this = scope:former_de_jure_liege
							}
						}
						NOR = {
							this = scope:puppet_or_actor
							this = scope:recipient
						}
					}
					add_opinion = {
						target = scope:puppet_or_actor
						modifier = ruled_against_my_diocese_opinion
						opinion = -25
					}
				}
				every_subordinate = {
					limit = {
						capital_province.county ?= {
							any_this_title_or_de_jure_above = {
								this = scope:recipient.primary_title
							}
						}
						NOR = {
							this = scope:puppet_or_actor
							this = scope:recipient
						}
					}
					add_opinion = {
						target = scope:puppet_or_actor
						modifier = ruled_in_favor_of_my_diocese_opinion
						opinion = 25
					}
				}
			}
		}
		
		scope:recipient = {
			show_as_tooltip = {
				ecclesiastical_de_jure_shifting_effect = {
					DE_JURE_MASTER = scope:recipient
					CLERIC = scope:puppet_or_actor
				}
			}
		}

		scope:puppet_or_actor = {
			trigger_event = pam_interactions_events.0096
		}
	}

	on_decline = {
		if = {
			limit = {
				scope:recipient = {
					is_ai = no
				}
			}
			scope:puppet_or_actor = {
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ecclesiastical_de_jure_shifting_grant_interaction_decline_toast
					left_icon = scope:recipient
				}
				add_opinion = {
					target = scope:recipient
					modifier = refusal_opinion
					opinion = -30
				}
			}
			if = {
				limit = {
					scope:is_puppet_action ?= yes
					scope:actor != scope:recipient
				}
				scope:actor = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = ecclesiastical_de_jure_shifting_grant_interaction_decline_toast_puppeteer
						left_icon = scope:puppet_or_actor
						right_icon = scope:recipient
					}
				}
			}
			if = {
				limit = {
					scope:target.de_jure_liege.holder ?= {
						NOR = {
							this = scope:puppet_or_actor
							this = scope:recipient
						}
					}
				}
				scope:target.de_jure_liege.holder ?= {
					add_opinion = {
						target = scope:recipient
						modifier = respected_de_jure_opinion
						opinion = 50
					}
				}
			}
		}
	}

	send_options_exclusive = no

	ai_targets = {
		ai_recipients = neighboring_rulers_including_tributary_borders
		ai_recipients = dynasty
		ai_recipients = realm_characters
		ai_recipients = subordinates
		ai_recipients = rulers_in_clerical_region
		max = 5
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 120
		kingdom = 60
		empire = 60
		hegemony = 60
	}

	ai_will_do = {
		base = 5
		modifier = { # Peace of God: settling de jure claims by decree forestalls the wars they would otherwise cause
			add = 25
			scope:puppet_or_actor.rite ?= {
				rite_has_parameter = tenet_peace_of_god_clergy_peacemaking
			}
		}
		modifier = {
			exists = scope:target
			scope:recipient = {
				completely_controls = scope:target
			}
			add = 20
		}
		modifier = {
			exists = scope:target
			scope:target = {
				any_de_jure_county = {
					percent >= 0.5
					holder ?= {
						target_is_same_character_or_above = scope:recipient
					}
				}
			}
			add = 10
		}
		modifier = {
			scope:recipient = {
				has_any_good_relationship_with_character_trigger = { CHARACTER = scope:puppet_or_actor }
			}
			add = 75
		}
		modifier = {
			scope:recipient = scope:puppet_or_actor
			add = 100
		}
		modifier = {
			NOT = { scope:recipient = scope:puppet_or_actor }
			scope:target ?= {
				any_de_jure_county = {
					this = scope:puppet_or_actor.capital_county
					scope:puppet_or_actor.culture = capital_county.culture
				}
			}
			factor = 0.1
		}
		modifier = {
			OR = {
				ai_energy < 0
				AND = {
					scope:target.de_jure_liege.holder ?= {
						NOR = {
							this = scope:puppet_or_actor
							this = scope:recipient
						}
					}
					has_any_good_relationship_with_character_trigger = { CHARACTER = scope:target.de_jure_liege.holder }
				}
			}
			factor = 0
		}
	}
}



# A theocrat demands that a secular ruler put aside a spouse, citing an offence against the faith (real or invented).
demand_divorce_interaction = {
	category = interaction_category_religion
	icon = icon_marriage
	interface_priority = 52
	use_diplomatic_range = no
	ai_maybe = yes
	popup_on_receive = yes

	desc = demand_divorce_interaction_desc
	send_name = SEND_DEMAND
	prompt = demand_divorce_prompt

	notification_text = {
		desc = DEMAND_DIVORCE_NOTIFICATION
		first_valid = {
			triggered_desc = {
				trigger = {
					demand_divorce_marriage_incestuous_trigger = { RULER = scope:recipient SPOUSE = scope:secondary_recipient }
				}
				desc = DEMAND_DIVORCE_NOTIFICATION_INCESTUOUS
			}
			triggered_desc = {
				trigger = {
					demand_divorce_marriage_same_sex_trigger = { RULER = scope:recipient SPOUSE = scope:secondary_recipient }
				}
				desc = DEMAND_DIVORCE_NOTIFICATION_SAME_SEX
			}
			triggered_desc = {
				trigger = {
					demand_divorce_spouse_heathen_trigger = { RULER = scope:recipient SPOUSE = scope:secondary_recipient }
				}
				desc = DEMAND_DIVORCE_NOTIFICATION_HEATHEN
			}
			triggered_desc = {
				trigger = {
					demand_divorce_spouse_heretic_trigger = { RULER = scope:recipient SPOUSE = scope:secondary_recipient }
				}
				desc = DEMAND_DIVORCE_NOTIFICATION_HERETIC
			}
			triggered_desc = {
				trigger = {
					demand_divorce_spouse_infidelity_trigger = { RULER = scope:recipient SPOUSE = scope:secondary_recipient }
				}
				desc = DEMAND_DIVORCE_NOTIFICATION_INFIDELITY
			}
			triggered_desc = {
				trigger = {
					demand_divorce_marriage_polygamous_trigger = { RULER = scope:recipient SPOUSE = scope:secondary_recipient }
				}
				desc = DEMAND_DIVORCE_NOTIFICATION_POLYGAMY
			}
			desc = DEMAND_DIVORCE_NOTIFICATION_PRETEXT
		}
	}

	cooldown_against_recipient = { years = 5 }

	is_available = {
		trigger_if = {
			limit = {
				is_ai = yes
			}
			piety_level >= medium_piety_level
			NOT = { has_trait = excommunicated }
		}
		pam_is_clergy_ruler_trigger = yes
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:recipient = {
			this != scope:actor
			is_landed = yes
			is_married = yes
			is_valid_demand_church_succession_target_trigger = yes
			faith ?= scope:actor.faith
			primary_title ?= {
				tier >= tier_county
			}
		}
		# Rulers already served a divorce demand by any clergy are off-limits for a decade. Player actors are deliberately not bound by this.
		trigger_if = {
			limit = {
				scope:actor = { is_ai = yes }
			}
			scope:recipient = {
				NOT = { has_variable = demand_divorce_recently_demanded }
			}
		}
	}

	populate_recipient_list = {
		scope:recipient = {
			every_spouse = {
				limit = {
					this != scope:actor
					is_concubine = no
				}
				add_to_list = characters
			}
		}
	}

	has_valid_target_showing_failures_only = {
		exists = scope:secondary_recipient
		scope:secondary_recipient = {
			this != scope:actor
			is_spouse_of = scope:recipient
			is_concubine = no
			NOT = { has_strong_hook = scope:recipient }
		}
		scope:recipient = {
			custom_tooltip = {
				text = demand_divorce_family_widow_tt
				NOT = {
					var:family_widow_forbidden_divorce ?= scope:secondary_recipient
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_available_adult = yes
			NOT = { has_trait = excommunicated }
			NOT = { is_at_war_with = scope:recipient }
		}
		#Range: the Head of Faith reaches anyone, archbishops their clerical region, and all theocrats their own top realm
		trigger_if = {
			limit = {
				scope:actor = {
					NOT = { religious_head_or_challenger ?= this }
					any_held_title = { has_clerical_region = yes }
				}
			}
			custom_tooltip = {
				text = demand_divorce_archbishop_range_tt
				OR = {
					scope:recipient.top_liege ?= scope:actor.top_liege
					scope:recipient = {
						OR = {
							capital_county ?= {
								clerical_region_title ?= { holder = scope:actor }
							}
							location.county ?= {
								clerical_region_title ?= { holder = scope:actor }
							}
						}
					}
				}
			}
		}
		trigger_else_if = {
			limit = {
				scope:actor = {
					NOT = { religious_head_or_challenger ?= this }
				}
			}
			custom_tooltip = {
				text = demand_divorce_realm_range_tt
				scope:recipient.top_liege ?= scope:actor.top_liege
			}
		}
		trigger_else = {
			always = yes
		}
		# The marriage must be one the recipient could lawfully end.
		custom_tooltip = {
			text = demand_divorce_culture_forbids_tt
			NOT = {
				scope:recipient.culture = {
					has_cultural_parameter = cannot_divorce
				}
			}
		}
		NOT = {
			scope:recipient.rite = {
				rite_has_doctrine = doctrine_divorce_disallowed
			}
		}
	}

	cost = {
		piety = {
			value = minor_piety_value
			if = {
				limit = {
					scope:recipient.highest_held_title_tier >= tier_kingdom
				}
				value = major_piety_value
			}
			if = {
				limit = {
					scope:actor = {
						domicile ?= { has_domicile_parameter = estate_cheaper_divorce }
					}
				}
				multiply = ecclesiastical_domicile_cheaper_divorce_mult
			}
		}
	}

	on_send = {
		# Shields the recipient from being dogpiled by every clergyman in reach; only AI actors respect it (see is_shown).
		scope:recipient = {
			set_variable = {
				name = demand_divorce_recently_demanded
				years = 10
			}
		}
	}

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = demand_divorce_actor_complied_toast
				left_icon = scope:recipient
				right_icon = scope:secondary_recipient
				scope:recipient = {
					divorce_effect = {
						DIVORCER = scope:recipient
						DIVORCEE = scope:secondary_recipient
					}
					add_opinion = {
						target = scope:actor
						modifier = demanded_divorce_opinion
					}
				}
				scope:secondary_recipient = {
					add_opinion = {
						target = scope:actor
						modifier = demanded_divorce_opinion
					}
				}
			}
		}
		scope:recipient = {
			add_piety = minor_piety_value
			change_spiritual_fulfillment = minor_spiritual_fulfillment_value
			# Remarrying straight out of a Church-dissolved union makes a mockery of the ruling; the AI waits it out.
			set_variable = {
				name = pam_clerical_divorce_enforced
				years = 5
			}
		}
	}

	on_decline = {
		scope:recipient = {
			add_piety = medium_piety_loss
			change_spiritual_fulfillment = medium_spiritual_fulfillment_loss
			add_opinion = {
				target = scope:actor
				modifier = demanded_divorce_opinion
			}
		}
		scope:secondary_recipient = {
			add_opinion = {
				target = scope:actor
				modifier = demanded_divorce_opinion
			}
		}
		scope:actor = {
			add_opinion = {
				target = scope:recipient
				modifier = defied_divorce_demand_opinion
			}
			hidden_effect = {
				trigger_event = pam_interactions_events.0111
			}
		}
	}

	ai_targets = {
		ai_recipients = rulers_in_clerical_region
		ai_recipients = neighboring_rulers
		ai_recipients = scripted_relations
	}
	ai_targets = {
		ai_recipients = peer_vassals
		ai_recipients = domicile_location_top_realm_vassals
		max = 20
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 120
		duchy = 60
		kingdom = 36
		empire = 12
		hegemony = 12
	}

	ai_will_do = {
		base = 0

		# Rivalry needs no theology.
		modifier = {
			add = 100
			scope:actor = { has_relation_rival = scope:recipient }
		}
		# The pious police marriages that offend the faith.
		modifier = {
			add = 60
			scope:actor.ai_zeal >= medium_positive_ai_value
			demand_divorce_marriage_incestuous_trigger = { RULER = scope:recipient SPOUSE = scope:secondary_recipient }
		}
		modifier = {
			add = 50
			scope:actor.ai_zeal >= medium_positive_ai_value
			demand_divorce_spouse_heathen_trigger = { RULER = scope:recipient SPOUSE = scope:secondary_recipient }
		}
		modifier = {
			add = 20
			scope:actor.ai_zeal >= medium_positive_ai_value
			demand_divorce_spouse_heretic_trigger = { RULER = scope:recipient SPOUSE = scope:secondary_recipient }
		}
		modifier = {
			add = 40
			scope:actor.ai_zeal >= medium_positive_ai_value
			demand_divorce_spouse_infidelity_trigger = { RULER = scope:recipient SPOUSE = scope:secondary_recipient }
		}
		modifier = {
			add = 40
			scope:actor.ai_zeal >= medium_positive_ai_value
			demand_divorce_marriage_same_sex_trigger = { RULER = scope:recipient SPOUSE = scope:secondary_recipient }
		}
		modifier = {
			add = 30
			scope:actor.ai_zeal >= medium_positive_ai_value
			demand_divorce_marriage_polygamous_trigger = { RULER = scope:recipient SPOUSE = scope:secondary_recipient }
		}
		# Don't shake down friends, lovers, close family, or anyone the theocrat is genuinely fond of.
		modifier = {
			factor = 0
			scope:actor = {
				OR = {
					has_relation_friend = scope:recipient
					has_relation_lover = scope:recipient
					is_close_family_of = scope:recipient
					opinion = {
						target = scope:recipient
						value >= 30
					}
				}
			}
		}
	}

	ai_accept = {
		base = 0

		modifier = {
			add = 50
			desc = demand_divorce_ai_accept_authority_reason
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_1
			desc = ESTATE_DEMAND_DIVORCE_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_easier_demand_divorce_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_2
			desc = ESTATE_DEMAND_DIVORCE_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_easier_demand_divorce_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_minor_value_3
			desc = ESTATE_DEMAND_DIVORCE_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_easier_demand_divorce_3
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_1
			desc = ESTATE_DECRETALS_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_divorce_decretals_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_2
			desc = ESTATE_DECRETALS_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_divorce_decretals_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_3
			desc = ESTATE_DECRETALS_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_divorce_decretals_3
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_1
			desc = ESTATE_CHANCERY_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_chancery_divorce_1
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_2
			desc = ESTATE_CHANCERY_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_chancery_divorce_2
				}
			}
		}
		modifier = {
			add = ecclesiastical_domicile_acceptance_micro_value_3
			desc = ESTATE_CHANCERY_REASON
			scope:actor = {
				domicile ?= {
					has_domicile_parameter = estate_chancery_divorce_3
				}
			}
		}
		ecclesiastical_domicile_cathedral_awe_modifier = yes
		# A true offence is difficult to deny.
		modifier = {
			add = 25
			desc = demand_divorce_ai_accept_offence_reason
			demand_divorce_marriage_offensive_trigger = { RULER = scope:recipient SPOUSE = scope:secondary_recipient }
		}
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1
			desc = AI_OPINION_REASON
		}
		# A beloved spouse is worth defying the faith for.
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:secondary_recipient
			multiplier = -1
			desc = AI_OPINION_REASON
		}
		# A shepherd of another rite carries less weight.
		modifier = {
			add = -30
			desc = demand_divorce_ai_accept_rite_reason
			scope:actor.rite != scope:recipient.rite
		}
		ai_value_modifier = {
			who = scope:recipient
			ai_zeal = 0.5
		}
		modifier = {
			add = -60
			desc = demand_divorce_ai_accept_rival_reason
			scope:recipient = { has_relation_rival = scope:actor }
		}
	}
}

###############################################
# Holy Myron

# Gift a charge of your Holy Myron to another ruler: a fresh single-charge ampulla is filled from yours
pam_give_holy_myron_interaction = {
	category = interaction_category_religion
	icon = religious
	interface_priority = 35

	desc = pam_give_holy_myron_interaction_desc

	auto_accept = yes

	cooldown_against_recipient = { years = 5 }

	is_available = {
		pam_has_usable_holy_myron_trigger = yes
		has_pam_dlc_trigger = yes
		is_christian_trigger = yes
		rite ?= { rite_has_parameter = tenet_holy_myron_artifact_interaction_unlock }
		trigger_if = {
			limit = { is_ai = yes }
			any_character_artifact = {
				pam_is_holy_myron_artifact_trigger = yes
				trigger_if = {
					limit = { has_variable = pam_holy_myron_charges }
					var:pam_holy_myron_charges >= 3
				}
				trigger_else = {
					always = no
				}
			}
		}
	}

	is_shown = {
		scope:actor != scope:recipient
		scope:recipient = {
			is_ruler = yes
			faith.religion ?= scope:actor.faith.religion
			pam_has_usable_holy_myron_trigger = no
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_imprisoned = no
		}
		scope:recipient = {
			is_adult = yes
			is_imprisoned = no
		}
	}

	on_accept = {
		scope:actor = {
			pam_holy_myron_spend_warning_effect = yes
			hidden_effect = {
				pam_save_holy_myron_artifact_effect = yes
				pam_holy_myron_consume_charge_effect = {
					ARTIFACT = scope:pam_holy_myron_artifact
				}
			}
			add_piety = medium_piety_gain
			if = {
				limit = { is_playable_character = yes }
				change_spiritual_fulfillment = medium_spiritual_fulfillment_value
			}
		}
		scope:recipient = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = pam_give_holy_myron_recipient_toast
				left_icon = scope:actor
				custom_tooltip = pam_give_holy_myron_recipient_tt
				hidden_effect_new_object = {
					pam_create_holy_myron_artifact_effect = {
						OWNER = scope:recipient
						CREATOR = scope:actor
						RARITY = common
					}
				}
			}
			add_opinion = {
				target = scope:actor
				modifier = grateful_opinion
				opinion = 20
			}
		}
	}

	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = peer_vassals
		ai_recipients = liege
		ai_recipients = family
		ai_recipients = head_of_faith
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency = 120

	ai_will_do = {
		base = 15
		modifier = {
			add = 15
			has_trait = generous
		}
		modifier = {
			add = 15
			has_trait = zealous
		}
		modifier = {
			add = {
				value = 10
				multiply = 2
			}
			opinion = {
				target = scope:recipient
				value >= 50
			}
		}
		modifier = {
			factor = 0
			has_trait = greedy
		}
		modifier = {
			factor = 0
			has_trait = cynical
		}
	}
}

seek_communion_interaction = {
	category = interaction_category_religion
	icon = religious
	interface_priority = 50
	use_diplomatic_range = no

	desc = seek_communion_interaction_desc
	notification_text = seek_communion_interaction_notification

	greeting = positive
	popup_on_receive = yes
	ai_min_reply_days = 3
	ai_max_reply_days = 10

	cooldown_against_recipient = { years = 10 }
	
	is_available = {
		is_christian_trigger = yes
		faith ?= {
			trigger_if = {
				limit = { exists = religious_head }
				religious_head = root
			}
			trigger_else = {
				main_rite.head_of_rite = root
			}
			NOR = {
				has_doctrine = special_doctrine_ecumenical_christian
				has_doctrine = special_doctrine_ecumenical_miaphysite
			}
		}
		has_pam_dlc_trigger = yes
	}

	is_shown = {
		scope:actor != scope:recipient
		scope:recipient = {
			OR = {
				faith = faith:catholic
				faith = faith:christian_faith
			}
			any_held_title = { is_head_of_faith = yes }
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_adult = yes
			is_imprisoned = no
			NOT = { is_at_war_with = scope:recipient }
		}
		scope:recipient = {
			is_adult = yes
			is_imprisoned = no
			is_incapable = no
		}
	}

	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"
	send_options_exclusive = no

	on_accept = {
		scope:actor = {
			if = {
				limit = { scope:hook = yes }
				use_hook = scope:recipient
			}
			show_as_tooltip = { pam_seek_communion_reconcile_faith_effect = yes }
			trigger_event = pam_interactions_events.0130
			faith = {
				every_faith_character = {
					limit = {
						is_ruler = yes
						this != scope:actor
					}
					trigger_event = { id = pam_interactions_events.0130 days = 1 }
				}
			}
		}
	}

	on_decline = {
		scope:actor = {
			trigger_event = pam_interactions_events.0131
		}
	}

	ai_targets = {
		ai_recipients = other_faith_heads
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 24
		duchy = 24
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_will_do = {
		base = 20

		modifier = {
			add = 30
			situation:the_christian_church ?= { situation_current_phase = concord }
		}
		modifier = {
			add = -20
			scope:actor = { has_trait = arrogant }
		}
		modifier = {
			add = -40
			scope:actor = { has_trait = zealous }
		}
		modifier = {
			add = 20
			scope:actor = { has_trait = content }
		}
		modifier = {
			add = 20
			scope:actor = { has_trait = humble }
		}
		modifier = { # More likely when the heresy has not drifted far from Catholic practice
			add = {
				value = "scope:actor.faith.main_rite.divergence(scope:recipient.faith.main_rite)"
				multiply = -0.5
			}
		}
		modifier = {
			scope:hook = yes
			add = 50
		}
	}

	ai_accept = {
		base = -20

		modifier = {
			add = 30
			desc = SCHEME_WEAK_HOOK_USED
			scope:hook = yes
			scope:actor = { NOT = { has_strong_hook = scope:recipient } }
		}
		modifier = {
			add = 50
			desc = SCHEME_STRONG_HOOK_USED
			scope:hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
		}
		modifier = {
			add = 30
			desc = CHRISTIAN_CHURCH_PHASE_REASON
			situation:the_christian_church ?= { situation_current_phase = concord }
		}
		modifier = {
			add = -40
			desc = SEEK_COMMUNION_ZEALOUS_REASON
			scope:recipient = { has_trait = zealous }
		}
		modifier = {
			add = 25
			desc = SEEK_COMMUNION_FORGIVING_REASON
			scope:recipient = { has_trait = forgiving }
		}
		modifier = {
			add = -30
			desc = SEEK_COMMUNION_EXCOMMUNICATED_REASON
			scope:actor = { has_trait = excommunicated }
		}
		modifier = {
			add = 20
			desc = SEEK_COMMUNION_PIOUS_PETITIONER_REASON
			scope:actor = { piety_level >= 3 }
		}
		modifier = { # Halved so that even a wholly divergent heresy can still be argued back in
			add = {
				value = "scope:actor.faith.main_rite.divergence(scope:recipient.faith.main_rite)"
				multiply = -0.5
			}
			desc = SEEK_COMMUNION_DIVERGENCE_REASON
		}
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
		}
	}
}

pam_destroy_monastic_order_interaction = {
	category = interaction_category_religion
	icon = pam_destroy_monastic_order
	interface_priority = 39

	desc = pam_destroy_monastic_order_interaction_desc

	auto_accept = { always = yes }
	cooldown = { years = 10 }

	is_available = {
		faith.religious_head ?= this
		has_pam_dlc_trigger = yes
		is_adult = yes
	}

	is_shown = {
		scope:recipient = {
			this != scope:actor
			government_has_flag = government_is_monastic_holy_order
			holy_order ?= {
				order_faith ?= scope:actor.faith
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_available_quick = {
				adult = yes
				incapable = no
				imprisoned = no
				hostage = no
			}
		}
		custom_tooltip = {
			text = pam_destroy_monastic_order_at_peace_tt
			scope:recipient = {
				is_at_war = no
			}
		}
	}

	cost = {
		piety = massive_piety_value
	}

	on_accept = {
		scope:recipient.holy_order ?= {
			save_scope_as = pam_dissolved_order
			title = { save_scope_as = pam_dissolved_order_title }
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = pam_destroy_monastic_order_interaction_toast
				left_icon = scope:actor
				right_icon = scope:recipient
				custom_tooltip = {
					text = pam_destroy_monastic_order_dissolved_tt
					hidden_effect = {
						scope:pam_dissolved_order = {
							every_leased_title = {
								revoke_lease = yes
							}
						}
					}
				}
				scope:recipient = {
					add_opinion = {
						target = scope:actor
						modifier = revoked_order_lease_opinion
						opinion = -75
					}
				}
				scope:actor.faith ?= {
					every_faith_holy_order = {
						custom = custom.every_other_monastic_order_leader
						limit = {
							this != scope:pam_dissolved_order
							is_monastic_order_trigger = yes
						}
						leader ?= {
							add_opinion = {
								target = scope:actor
								modifier = revoked_order_lease_opinion
								opinion = -30
							}
						}
					}
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = faith_holy_order_leaders
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 48
		kingdom = 24
		empire = 24
		hegemony = 24
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = 100
			scope:recipient.holy_order ?= {
				order_tenet ?= {
					scope:actor.rite ?= {
						has_tenet_status = {
							tenet = prev
							status = prohibited
						}
					}
				}
			}
		}
		modifier = {
			add = 100
			scope:recipient = { has_trait = excommunicated }
		}
		modifier = { # Never against your own
			factor = 0
			scope:actor = {
				OR = {
					has_relation_friend = scope:recipient
					has_relation_best_friend = scope:recipient
					is_any_family_relation_or_spouse_trigger = { CHARACTER = scope:recipient }
				}
			}
		}
	}
}
