liege_modify_vassal_contract_interaction = {
	special_interaction = liege_modify_vassal_contract
	interface = modify_vassal_contract
	category = interaction_category_vassal
	common_interaction = yes
	icon = icon_contract_modification_single
	interface_priority = 5

	send_name = "modify_vassal_contract_interaction_SEND"
	desc = liege_modify_vassal_contract_interaction_desc

	force_notification = yes
	notification_text = MODIFY_VASSAL_CONTRACT_NOTIFICATION_TO_VASSAL

	is_shown = {
		scope:recipient = {
			this != scope:actor
			liege ?= scope:actor # this excludes tributary contracts by default
			is_ruler = yes
			vassal_contract_has_modifiable_obligations = yes
			NOT = { government_allows = administrative }
			NOT = { government_has_flag = government_is_nomadic }
		}
	}

	is_valid_showing_failures_only = {
		NOT = { scope:actor = { is_at_war_with = scope:recipient } }
	}

	can_send = {
		#Mandala gets special treatment
		trigger_if = {
			limit = { 
				scope:actor = { government_has_flag = government_is_mandala }
			}
			custom_tooltip = {
				text = liege_modify_vassal_contract_mandala_cooldown
				NOT = {
					scope:recipient = { var:liege_recently_adjusted_mandala_vassal_contract ?= scope:actor }
				}
			}
			scope:actor = {
				has_changed_contract_obligation_trigger = yes

				custom_description = {
					text = "liege_modify_vassal_contract_cannot_exceed_tyranny_cap"
					object = scope:actor
					NOT = {
						vassal_obligation_increase_tyranny_gain_multiplier > 1
					}
				}

				# Cannot change more than three things at once
				custom_description = {
					text = "vassal_modify_vassal_contract_obligation_change_limit"
					value = list_size:changed_obligations
					list_size:changed_obligations <= max_contract_changes
				}

				# If the trade without the hook usage is already in the vassal's favour or fair then don't waste your hook
				save_temporary_scope_value_as = {
					name = obligations_favoring_vassal
					value = scope:recipient.count_obligation_improvements_for_vassal
				}
				trigger_if = {
					limit = { scope:obligations_favoring_vassal > 0 }
					custom_description = {
						text = "vassal_modify_vassal_contract_unnecessary_hook_usage_vassal_favor"
						object = scope:recipient
						value = scope:obligations_favoring_vassal
						NOT = { always = scope:hook }
					}
				}
				trigger_else_if = {
					limit = { scope:obligations_favoring_vassal = 0 }
					custom_description = {
						text = "vassal_modify_vassal_contract_unnecessary_hook_usage_equal"
						object = scope:recipient
						NOT = { always = scope:hook }
					}
				}
				trigger_else = {} # Otherwise we're fine!
			}
		}
		#The rest
		trigger_else_if = { #If they're blocked we don't want to show anything else
			limit = {
				scope:recipient = {
					subject_contract_is_blocked_from_modification = yes
				}
			}
			scope:recipient = {
				subject_contract_is_blocked_from_modification = no
			}
		}
		trigger_else = {
			scope:actor = {
				has_changed_contract_obligation_trigger = yes

				custom_description = {
					text = "liege_modify_vassal_contract_cannot_exceed_tyranny_cap"
					object = scope:actor
					NOT = {
						vassal_obligation_increase_tyranny_gain_multiplier > 1
					}
				}

				# Cannot change more than three things at once
				custom_description = {
					text = "vassal_modify_vassal_contract_obligation_change_limit"
					value = list_size:changed_obligations
					list_size:changed_obligations <= max_contract_changes
				}

				# If the trade without the hook usage is already in the vassal's favour or fair then don't waste your hook
				save_temporary_scope_value_as = {
					name = obligations_favoring_vassal
					value = scope:recipient.count_obligation_improvements_for_vassal
				}
				trigger_if = {
					limit = { scope:obligations_favoring_vassal > 0 }
					custom_description = {
						text = "vassal_modify_vassal_contract_unnecessary_hook_usage_vassal_favor"
						object = scope:recipient
						value = scope:obligations_favoring_vassal
						NOT = { always = scope:hook }
					}
				}
				trigger_else_if = {
					limit = { scope:obligations_favoring_vassal = 0 }
					custom_description = {
						text = "vassal_modify_vassal_contract_unnecessary_hook_usage_equal"
						object = scope:recipient
						NOT = { always = scope:hook }
					}
				}
				trigger_else = {} # Otherwise we're fine!
			}
		}
	}

	auto_accept = yes
	on_accept = {
		hidden_effect = {
			# Struggle Catalysts
			## We work these out first so they're not invalidated by the actual effect block.
			if = {
				limit = {
					catalyst_granted_powerful_diff_faith_vassal_religious_protection_preliminary_trigger = { CHAR = scope:recipient }
					scope:actor = {
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_granted_powerful_diff_faith_vassal_religious_protection
								CHAR = scope:recipient
							}
						}
					}
				}
				scope:actor = {
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_granted_powerful_diff_faith_vassal_religious_protection
								CHAR = scope:recipient
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_granted_powerful_diff_faith_vassal_religious_protection
							character = scope:actor
						}
					}
				}
			}
			if = {
				limit = {
					catalyst_revoked_powerful_diff_faith_vassal_religious_protection_preliminary_trigger = { CHAR = scope:recipient }
					scope:actor = {
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_revoked_powerful_diff_faith_vassal_religious_protection
								CHAR = scope:recipient
							}
						}
					}
				}
				scope:actor = {
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_revoked_powerful_diff_faith_vassal_religious_protection
								CHAR = scope:recipient
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_revoked_powerful_diff_faith_vassal_religious_protection
							character = scope:actor
						}
					}
				}
			}

			# Improving contract catalyst
			if = {
				limit = {
					scope:recipient.count_obligation_improvements_for_vassal > 0
					scope:actor = {
						is_diff_faith_or_culture_trigger = {
							CHAR = scope:recipient
							STATUS = involved
						}
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_grant_privilege_to_diff_faith_culture_vassal
								CHAR = scope:recipient
							}
						}
					}
				}
				scope:actor = {
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_grant_privilege_to_diff_faith_culture_vassal
								CHAR = scope:recipient
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_grant_privilege_to_diff_faith_culture_vassal
							character = scope:actor
						}
					}
				}
			}
		}

		# Enact changes.
		scope:actor = {
			send_interface_message = {
				type = msg_vassal_contract_change
				title = modify_vassal_contract_interaction_notification
				right_icon = scope:recipient
				# Add tyranny for each level increased. Can spend one hook to avoid one level of tyranny hit.
				add_tyranny = vassal_obligation_increase_tyranny_gain
				if = {
					limit = { vassal_obligation_increase_tyranny_gain != 0 }
					stress_impact = {
						just = medium_stress_impact_gain
						generous = medium_stress_impact_gain
					}
				}
				if = {
					limit = {
						always = scope:hook
					}
					use_hook = scope:recipient
					add_achievement_flag_effect = { FLAG = achievement_fine_print_flag }
				}

				scope:recipient = {
					hidden_effect = {
						set_subject_contract_modification_blocked = yes
					}
					set_variable = {
						name = liege_recently_adjusted_mandala_vassal_contract
						value = scope:actor
						years = mandala_vassal_obligation_cooldown_years
					}
				}

				every_in_list = {
					list = changed_obligations

					save_scope_as = obligation

					scope:recipient = {
						vassal_contract_set_obligation_level = {
							type = scope:obligation.vassal_contract_type
							level = scope:obligation
						}
					}

				}
			}
		}

		# Additional Flavor Titles
		scope:recipient = { additional_flavor_check_effect = yes }
	}

	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
}

vassal_modify_vassal_contract_interaction = {
	special_interaction = liege_modify_vassal_contract
	interface = modify_vassal_contract
	category = interaction_category_vassal
	common_interaction = yes
	icon = icon_contract_modification_single

	send_name = "modify_vassal_contract_interaction_SEND"
	desc = vassal_modify_vassal_contract_interaction_desc

	force_notification = yes
	notification_text = MODIFY_VASSAL_CONTRACT_NOTIFICATION_TO_LIEGE

	redirect = {
		# need to reverse the role for the UI to work properly
		scope:recipient = {
			save_scope_as = secondary_recipient
		}
		scope:actor = {
			save_scope_as = recipient
		}

		scope:secondary_recipient = {
			save_scope_as = actor
		}
	}

	is_shown = {
		scope:recipient = {
			top_liege != this
			this != scope:actor
			liege ?= scope:actor # this excludes tributary contracts by default
			vassal_contract_has_modifiable_obligations = yes
			NOT = { government_allows = administrative }
			NOT = { government_has_flag = government_is_nomadic }
		}
	}

	is_valid_showing_failures_only = {
		NOT = { scope:recipient = { is_at_war_with = scope:actor } }
	}

	can_send = {
		#Mandala gets special treatment
		trigger_if = {
			limit = { 
				scope:recipient = { government_has_flag = government_is_mandala }
			}
			custom_tooltip = {
				text = vassal_modify_vassal_contract_mandala_cooldown
				NOT = {
					scope:actor = { var:vassal_recently_adjusted_mandala_vassal_contract ?= scope:recipient }
				}
			}
			scope:actor = {
				has_changed_contract_obligation_trigger = yes
			}

			scope:recipient = {
				# Must be an even trade overall
				trigger_if = {
					limit = {
						count_obligation_improvements_for_vassal_include_hook >= 0
					}
					custom_description = {
						text = "vassal_modify_vassal_contract_cannot_increase_obligation_level"
						object = scope:actor
						value = count_obligation_improvements_for_vassal_include_hook
						count_obligation_improvements_for_vassal_include_hook = 0
					}
				}

				# Cannot change more than three things at once
				custom_description = {
					text = "vassal_modify_vassal_contract_obligation_change_limit"
					value = list_size:changed_obligations
					list_size:changed_obligations <= max_contract_changes
				}
			}
		}
		#The rest
		trigger_else_if = { #If you're blocked we don't want to show anything else
			limit = {
				scope:recipient = {
					subject_contract_is_blocked_from_modification = yes
				}
			}
			scope:recipient = {
				subject_contract_is_blocked_from_modification = no
			}
		}
		trigger_else = {
			scope:actor = {
				has_changed_contract_obligation_trigger = yes
			}

			scope:recipient = {
				# Must be an even trade overall
				trigger_if = {
					limit = {
						count_obligation_improvements_for_vassal_include_hook >= 0
					}
					custom_description = {
						text = "vassal_modify_vassal_contract_cannot_increase_obligation_level"
						object = scope:actor
						value = count_obligation_improvements_for_vassal_include_hook
						count_obligation_improvements_for_vassal_include_hook = 0
					}
				}

				# Cannot change more than three things at once
				custom_description = {
					text = "vassal_modify_vassal_contract_obligation_change_limit"
					value = list_size:changed_obligations
					list_size:changed_obligations <= max_contract_changes
				}
			}
		}
	}

	auto_accept = yes

	on_accept = {
		# Enact changes.
		scope:recipient = {
			send_interface_message = {
				type = msg_vassal_contract_change
				title = modify_vassal_contract_interaction_notification
				right_icon = scope:actor
				if = {
					limit = { always = scope:hook }
					use_hook = scope:actor
					add_achievement_flag_effect = { FLAG = achievement_fine_print_flag }
				}

				hidden_effect = { set_subject_contract_modification_blocked = yes }

				every_in_list = {
					list = changed_obligations

					save_scope_as = obligation

					scope:recipient = {
						vassal_contract_set_obligation_level = {
							type = scope:obligation.vassal_contract_type
							level = scope:obligation
						}
					}
				}
			}
		}
		scope:actor = {
			set_variable = {
				name = vassal_recently_adjusted_mandala_vassal_contract
				value = scope:recipient
				years = mandala_vassal_obligation_cooldown_years
			}
		}
		# If there's a diarch involved, and they called in their change, that gets flagged.
		diarch_changed_own_contract_effect = yes

		hidden_effect = {
			# Struggle Catalysts
			## We work these out first so they're not invalidated by the actual effect block.
			if = {
				limit = {
					catalyst_granted_powerful_diff_faith_vassal_religious_protection_preliminary_trigger = { CHAR = scope:recipient }
					scope:actor = {
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_granted_powerful_diff_faith_vassal_religious_protection
								CHAR = scope:recipient
							}
						}
					}
				}
				scope:actor = {
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_granted_powerful_diff_faith_vassal_religious_protection
								CHAR = scope:recipient
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_granted_powerful_diff_faith_vassal_religious_protection
							character = scope:recipient
						}
					}
				}
			}
			# Improving contract catalyst
			if = {
				limit = {
					scope:recipient.count_obligation_improvements_for_vassal > 0
					scope:actor = {
						is_diff_faith_or_culture_trigger = {
							CHAR = scope:recipient
							STATUS = involved
						}
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_grant_privilege_to_diff_faith_culture_vassal
								CHAR = scope:recipient
							}
						}
					}
				}
				scope:actor = {
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_grant_privilege_to_diff_faith_culture_vassal
								CHAR = scope:recipient
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_grant_privilege_to_diff_faith_culture_vassal
							character = scope:actor
						}
					}
				}
			}
		}

		# Additional Flavor Titles
		scope:recipient = { additional_flavor_check_effect = yes }
	}

	send_option = {
		is_valid = {
			scope:recipient = {
				has_usable_hook = scope:actor
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	send_option = {
		is_shown = {
			scope:recipient = { is_diarch_of_target = scope:actor }
			scope:actor = { has_diarchy_parameter = diarch_gets_a_free_change_on_vassal_contract }
		}
		is_valid = {
			scope:recipient = {
				trigger_if = {
					limit = { has_variable_list = diarch_contract_rights_used_list }
					NOT = {
						is_target_in_variable_list = {
							name = diarch_contract_rights_used_list
							target = scope:actor
						}
					}
				}
			}
			scope:actor = { has_diarchy_active_parameter = diarch_gets_a_free_change_on_vassal_contract }
		}
		flag = diarch
		localization = CALL_IN_DIARCH_RIGHTS
	}
	should_use_extra_icon = {
		scope:recipient = { has_usable_hook = scope:actor }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"
	send_options_exclusive = no
}

ai_only_liege_modify_vassal_contract_interaction = {
	category = interaction_category_vassal
	send_name = "modify_vassal_contract_interaction_SEND"
	desc = liege_modify_vassal_contract_interaction_desc

	auto_accept = yes

	is_shown = {
		scope:actor = {
			is_ai = yes
			has_usable_hook = scope:recipient
		}
		scope:recipient = {
			this != scope:actor
			NOT = {
				has_strong_hook = scope:actor
			}
			liege ?= scope:actor # this excludes tributary contracts by default
			is_ruler = yes
			vassal_contract_can_be_modified_trigger = yes
			does_ai_liege_in_vassal_contract_desire_obligation_change = yes
		}
		NOT = { scope:actor = { is_at_war_with = scope:recipient } }
	}

	on_accept = {
		scope:actor = {
			stress_impact = {
				generous = minor_stress_impact_gain
			}
		}

		scope:recipient = {
			set_subject_contract_modification_blocked = yes
			trigger_event = char_interaction.0250
		}

		# Additional Flavor Titles
		scope:recipient = { additional_flavor_check_effect = yes }
	}

	ai_potential = {
		trigger_if = {
			limit = {
				NOT = { government_allows = administrative }
			}
			is_at_war = no
		}
	}

	ai_targets = {
		ai_recipients = vassals
	}
	
	ai_frequency_by_tier = {
		barony = 0
		county = 12
		duchy = 12
		kingdom = 24
		empire = 24
		hegemony = 36
	}

	ai_will_do = {
		base = 100

		modifier = {
			factor = 0
			scope:recipient = {
				OR = {
					AND = {
						scope:actor = {
							ai_greed <= high_positive_ai_value
						}
						has_relation_friend = scope:actor
					}
					has_relation_best_friend = scope:actor
					has_relation_soulmate = scope:actor
				}
			}
		}
	}
}

# AI only interaction for specifically Admin Province obligations
ai_only_liege_modify_vassal_contract_admin_province_interaction = {
	category = interaction_category_vassal
	send_name = "modify_vassal_contract_interaction_SEND"
	desc = liege_modify_vassal_contract_interaction_desc

	auto_accept = yes

	is_shown = {
		scope:actor = {
			is_ai = yes
			AND = {
				government_has_flag = government_uses_admin_province_obligations
				scope:recipient = { government_has_flag = government_uses_admin_province_obligations }
			}
		}
		scope:recipient = {
			this != scope:actor
			NOT = {
				has_strong_hook = scope:actor
			}
			liege ?= scope:actor # this excludes tributary contracts by default
			is_ruler = yes
			government_has_flag = government_uses_admin_province_obligations

			does_ai_liege_in_vassal_contract_desire_admin_province_obligation_change = yes
		}
		NOT = { scope:actor = { is_at_war_with = scope:recipient } }
	}

	on_accept = {
		scope:actor = {
			stress_impact = {
				generous = minor_stress_impact_gain
			}
		}

		scope:recipient = {
			trigger_event = char_interaction.0253
		}

		# Additional Flavor Titles
		scope:recipient = { additional_flavor_check_effect = yes }
	}

	ai_targets = {
		ai_recipients = vassals
		max = 10
	}

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

	is_available = {
		# This also blocks non-admin govs with admin vassals from changing province obligations... but we're OK with that.
		government_has_flag = government_uses_admin_province_obligations
	}

	ai_will_do = {
		base = 100
	}
}

ai_only_vassal_modify_vassal_contract_interaction = {
	category = interaction_category_vassal
	send_name = "modify_vassal_contract_interaction_SEND"
	desc = vassal_modify_vassal_contract_interaction_desc

	auto_accept = yes

	is_shown = {
		scope:actor = {
			is_ai = yes
			top_liege != this
			has_usable_hook = scope:recipient
			vassal_contract_can_be_modified_trigger = yes
			does_ai_vassal_in_vassal_contract_desire_obligation_change = yes
		}
		scope:recipient = {
			this != scope:actor
			liege ?= scope:actor # this excludes tributary contracts by default
			is_ruler = yes
			NOT = {
				has_strong_hook = scope:actor
			}
		}
		NOT = { scope:actor = { is_at_war_with = scope:recipient } }
	}

	on_accept = {
		scope:recipient = {
			trigger_event = char_interaction.0251
		}

		# Additional Flavor Titles
		scope:recipient = { additional_flavor_check_effect = yes }
	}

	ai_potential = {
		always = yes
	}

	ai_targets = {
		ai_recipients = liege
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 24
		duchy = 24
		kingdom = 24
		empire = 36
		hegemony = 0
	}

	ai_will_do = {
		base = 100

		modifier = {
			factor = 0
			scope:recipient = {
				OR = {
					AND = {
						scope:actor = {
							ai_greed <= high_positive_ai_value
						}
						has_relation_friend = scope:actor
					}
					has_relation_best_friend = scope:actor
					has_relation_soulmate = scope:actor
				}
			}
		}
	}
}

# Separate interactions are set up for Administrative - This is to help with localisation and some of the effects
admin_liege rep_liege_modify_vassal_contract_interaction = {
	special_interaction = liege_modify_vassal_contract
	interface = modify_vassal_contract
	category = interaction_category_vassal
	common_interaction = yes
	interface_priority = 1000
	icon = icon_contract_modification_single

	send_name = admin_liege rep_liege_modify_vassal_contract_interaction
	desc = admin_liege rep_liege_modify_vassal_contract_interaction_desc

	force_notification = yes
	notification_text = MODIFY_VASSAL_CONTRACT_NOTIFICATION_TO_VASSAL

	is_shown = {
		scope:recipient = {
			this != scope:actor
			OR = {
				is_landed = yes
				is_councillor_of = scope:actor.top_liege
			}
			liege ?= scope:actor # this excludes tributary contracts by default
			is_ruler = yes
			vassal_contract_has_modifiable_obligations = yes
			government_allows = administrative
			any_held_title = {
				OR = {
					tier >= holder.main_administrative_tier
					tier >= holder.min_title_maa_tier
				}
				is_noble_family_title = no
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			NOT = { is_at_war_with = scope:recipient }
			tgp_is_ceremonial_liege_trigger = no
		}
	}

	can_send = {
		trigger_if = { #If they're blocked we don't want to show anything else
			limit = {
				scope:recipient = {
					subject_contract_is_blocked_from_modification = yes
				}
			}
			scope:recipient = {
				subject_contract_is_blocked_from_modification = no
			}
		}
		trigger_else = {
			# There is no cooldown present - To make sure we somehow don't show both cooldowns at the same time, we split them into separate triggers
			trigger_if = {
				limit = {
					scope:recipient = {
						has_variable = admin_contract_cooldown
					}
				}
				custom_tooltip = {
					text = admin_contract_cooldown_desc
					scope:recipient = {
						NOT = { has_variable = admin_contract_cooldown }
					}
				}
			}
			trigger_else = {
				scope:actor = {
					has_changed_contract_obligation_trigger = yes
				}
			}
		}
	}

	auto_accept = yes
	on_accept = {
		hidden_effect = {
			# Struggle Catalysts
			## We work these out first so they're not invalidated by the actual effect block.
			if = {
				limit = {
					catalyst_granted_powerful_diff_faith_vassal_religious_protection_preliminary_trigger = { CHAR = scope:recipient }
					scope:actor = {
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_granted_powerful_diff_faith_vassal_religious_protection
								CHAR = scope:recipient
							}
						}
					}
				}
				scope:actor = {
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_granted_powerful_diff_faith_vassal_religious_protection
								CHAR = scope:recipient
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_granted_powerful_diff_faith_vassal_religious_protection
							character = scope:actor
						}
					}
				}
			}
			if = {
				limit = {
					catalyst_revoked_powerful_diff_faith_vassal_religious_protection_preliminary_trigger = { CHAR = scope:recipient }
					scope:actor = {
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_revoked_powerful_diff_faith_vassal_religious_protection
								CHAR = scope:recipient
							}
						}
					}
				}
				scope:actor = {
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_revoked_powerful_diff_faith_vassal_religious_protection
								CHAR = scope:recipient
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_revoked_powerful_diff_faith_vassal_religious_protection
							character = scope:actor
						}
					}
				}
			}

			# Improving contract catalyst
			if = {
				limit = {
					scope:recipient.count_obligation_improvements_for_vassal > 0
					scope:actor = {
						is_diff_faith_or_culture_trigger = {
							CHAR = scope:recipient
							STATUS = involved
						}
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_grant_privilege_to_diff_faith_culture_vassal
								CHAR = scope:recipient
							}
						}
					}
				}
				scope:actor = {
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_grant_privilege_to_diff_faith_culture_vassal
								CHAR = scope:recipient
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_grant_privilege_to_diff_faith_culture_vassal
							character = scope:actor
						}
					}
				}
			}
		}

		# Enact changes.
		scope:actor = {
			send_interface_message = {
				type = msg_vassal_contract_change
				title = modify_vassal_contract_interaction_notification
				right_icon = scope:recipient
				
				scope:recipient = {
					hidden_effect = {
						set_variable = {
							name = admin_contract_cooldown
							value = yes
							years = admin_contract_cooldown_value
						}
					}
				}

				every_in_list = {
					list = changed_obligations

					save_scope_as = obligation

					scope:recipient = {
						vassal_contract_set_obligation_level = {
							type = scope:obligation.vassal_contract_type
							level = scope:obligation
						}
						
						# Update the succession law for celestial province types if applicable - That way, we don't have to wait until the current law invalidates.
						if = {
							limit = {
								government_has_flag = government_is_celestial
								scope:obligation.vassal_contract_type = vassal_contract:celestial_provinces
							}
							
							if = {
								limit = {
									OR = {
										vassal_contract_has_flag = celestial_province_military
										vassal_contract_has_flag = celestial_province_protectorate
									}
									NOT = { has_realm_law = celestial_military_appointment_succession_law }
								}
								add_realm_law_skip_effects = celestial_military_appointment_succession_law
							}
							else_if = {
								limit = {
									OR = {
										vassal_contract_has_flag = celestial_province_standard
										vassal_contract_has_flag = celestial_province_industrial
										vassal_contract_has_flag = celestial_province_metropolitan
									}
									NOT = { has_realm_law = celestial_appointment_succession_law }
								}
								add_realm_law_skip_effects = celestial_appointment_succession_law
							}
						}
					}
				}
			}
		}

		# Additional Flavor Titles
		scope:recipient = { additional_flavor_check_effect = yes }
	}

	send_options_exclusive = no
}

admin_vassal_modify_vassal_contract_interaction = {
	special_interaction = vassal_modify_vassal_contract
	interface = modify_vassal_contract
	category = interaction_category_vassal
	interface_priority = 65
	common_interaction = yes
	icon = icon_contract_modification_single

	filter_tags = { admin_liege rep_liege }

	send_name = "admin_vassal_modify_vassal_contract_interaction_send"
	desc = admin_vassal_modify_vassal_contract_interaction_desc

	is_shown = {
		scope:actor = {
			top_liege != this
			this != scope:recipient
			liege ?= scope:recipient # this excludes tributary contracts by default
			vassal_contract_has_modifiable_obligations = yes
			government_allows = administrative
			tgp_is_ceremonial_liege_trigger = no
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			custom_tooltip = {
				text = admin_vassal_not_holding_a_theme_desc
				any_held_title = {
					OR = {
						tier >= holder.main_administrative_tier
						tier >= holder.min_title_maa_tier
					}
					is_noble_family_title = no
				}
			}
			NOT = { is_at_war_with = scope:recipient }
		}
	}

	can_send = {
		trigger_if = { #If you're blocked we don't want to show anything else (we don't really use this for admin, but we'll keep the logic, just in case)
			limit = {
				scope:actor = {
					subject_contract_is_blocked_from_modification = yes
				}
			}
			scope:actor = {
				subject_contract_is_blocked_from_modification = no
			}
		}
		trigger_else = {
			# There is no cooldown present - To make sure we somehow don't show both cooldowns at the same time, we split them into separate triggers
			trigger_if = {
				limit = {
					scope:actor = {
						has_variable = admin_contract_cooldown
					}
				}
				custom_tooltip = {
					text = admin_contract_cooldown_desc_vassal
					scope:actor = {
						NOT = { has_variable = admin_contract_cooldown }
					}
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = admin_contract_request_cooldown_desc
					scope:actor = {
						NOT = { has_variable = admin_contract_request_cooldown }
					}
				}
				scope:actor = {
					has_changed_contract_obligation_trigger = yes
				}
			}

			# You can afford the influence cost
			trigger_if = {
				limit = {
					NOR = {
						scope:hook = yes
						scope:dominant_family = yes
					}
				}
				scope:actor = {
					influence >= major_influence_value
				}
			}
		}
	}

	auto_accept = {
		custom_tooltip = {
			text = admin_vassal_force_obligation_change_desc
			OR = {
				scope:hook = yes
				scope:dominant_family = yes
				scope:diarch = yes
			}
		}
	}

	on_accept = {
		# Enact changes
		scope:actor = {
			send_interface_message = {
				type = msg_vassal_contract_change
				title = modify_vassal_contract_interaction_notification
				right_icon = scope:recipient

				# If you use a hook - Spend it
				if = {
					limit = { always = scope:hook }
					use_hook = scope:recipient
					add_achievement_flag_effect = { FLAG = achievement_fine_print_flag }
				}

				# If you didn't use a hook or leveraged your position as a Dominant Family, pay Influence
				if = {
					limit = {
						has_changed_contract_obligation_trigger = yes # Don't show the cost unless we actually change the contract
						NOR = {
							scope:hook = yes
							scope:dominant_family = yes
							scope:diarch = yes
						}
					}
					scope:actor = {
						change_influence = major_influence_loss
					}
				}

				# Activate cooldown - To prevent liege from changing it too soon
				hidden_effect = {
					set_variable = {
						name = admin_contract_cooldown
						value = yes
						years = admin_contract_cooldown_value
					}
				}

				every_in_list = {
					list = changed_obligations

					save_scope_as = obligation

					scope:actor = {
						vassal_contract_set_obligation_level = {
							type = scope:obligation.vassal_contract_type
							level = scope:obligation
						}
						
						# Update the succession law for celestial province types if applicable - That way, we don't have to wait until the current law invalidates.
						if = {
							limit = {
								government_has_flag = government_is_celestial
								scope:obligation.vassal_contract_type = vassal_contract:celestial_provinces
							}
							
							if = {
								limit = {
									OR = {
										vassal_contract_has_flag = celestial_province_military
										vassal_contract_has_flag = celestial_province_protectorate
									}
									NOT = { has_realm_law = celestial_military_appointment_succession_law }
								}
								add_realm_law_skip_effects = celestial_military_appointment_succession_law
							}
							else_if = {
								limit = {
									OR = {
										vassal_contract_has_flag = celestial_province_standard
										vassal_contract_has_flag = celestial_province_industrial
										vassal_contract_has_flag = celestial_province_metropolitan
									}
									NOT = { has_realm_law = celestial_appointment_succession_law }
								}
								add_realm_law_skip_effects = celestial_appointment_succession_law
							}
						}
					}
				}
			}
		}

		# If there's a diarch involved, and they called in their change, that gets flagged.
		diarch_changed_own_contract_effect = yes

		hidden_effect = {
			# Struggle Catalysts
			## We work these out first so they're not invalidated by the actual effect block.
			if = {
				limit = {
					catalyst_granted_powerful_diff_faith_vassal_religious_protection_preliminary_trigger = { CHAR = scope:recipient }
					scope:recipient = {
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_granted_powerful_diff_faith_vassal_religious_protection
								CHAR = scope:actor
							}
						}
					}
				}
				scope:recipient = {
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_granted_powerful_diff_faith_vassal_religious_protection
								CHAR = scope:actor
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_granted_powerful_diff_faith_vassal_religious_protection
							character = scope:actor
						}
					}
				}
			}
			# Improving contract catalyst
			if = {
				limit = {
					scope:actor.count_obligation_improvements_for_vassal > 0
					scope:recipient = {
						is_diff_faith_or_culture_trigger = {
							CHAR = scope:actor
							STATUS = involved
						}
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_grant_privilege_to_diff_faith_culture_vassal
								CHAR = scope:actor
							}
						}
					}
				}
				scope:recipient = {
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_grant_privilege_to_diff_faith_culture_vassal
								CHAR = scope:actor
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_grant_privilege_to_diff_faith_culture_vassal
							character = scope:recipient
						}
					}
				}
			}
		}
	}

	on_decline = {
		# Activate cooldown - You may only ask for it to be changed every so often (this mostly exists for MP, since you cannot send it to the AI unless they accept)
		hidden_effect = {
			scope:actor = {
				set_variable = {
					name = admin_contract_request_cooldown
					value = yes
					years = admin_contract_cooldown_value
				}
			}
		}
	}

	# Send Options
	# Hook
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	# Dominant Family
	send_option = {
		is_shown = {
			scope:actor = {
				house ?= { is_dominant_family = yes }
			}
		}
		flag = dominant_family
		localization = OPTION_DOMINANT_FAMILY
	}
	# Diarch
	send_option = {
		is_shown = {
			scope:actor = { is_diarch_of_target = scope:recipient }
		}
		is_valid = {
			scope:actor = {
				trigger_if = {
					limit = { has_variable_list = diarch_contract_rights_used_list }
					NOT = {
						is_target_in_variable_list = {
							name = diarch_contract_rights_used_list
							target = scope:recipient
						}
					}
				}
			}
		}
		flag = diarch
		localization = CALL_IN_DIARCH_RIGHTS
	}
	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_accept = {
		base = -25

		# Opinion Factor
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1
			desc = AI_OPINION_REASON
		}

		# Governor efficiency - Skilled governors are more likely to get accepted
		modifier = {
			add = scope:actor.governor_efficiency_presented
			desc = AI_GOVERNOR_EFFICIENCY
		}

		# Members of a powerful family are more likely to get accepted
		modifier = {
			scope:actor = {
				house ?= { is_powerful_family = yes }
				NOT = { house ?= scope:recipient.house }
			}
			add = 50
			desc = AI_POWERFUL_FAMILY
		}

		# Members of the emperors family are much more likely to get accepted
		modifier = {
			scope:actor = {
				house ?= scope:recipient.house
			}
			add = 60
			desc = AI_SAME_HOUSE
		}
	}
}

# Separate interactions are set up for Nomads - This is to help with localisation and some of the effects
nomad_liege_modify_vassal_contract_interaction = {
	special_interaction = liege_modify_vassal_contract
	interface = modify_vassal_contract
	category = interaction_category_vassal
	common_interaction = yes
	icon = icon_contract_modification_single

	send_name = nomad_liege_modify_vassal_contract_interaction
	desc = nomad_liege_modify_vassal_contract_interaction_desc

	force_notification = yes
	notification_text = MODIFY_VASSAL_CONTRACT_NOTIFICATION_TO_VASSAL

	is_shown = {
		scope:recipient = {
			NOT = { this = scope:actor }
			liege ?= scope:actor # this excludes tributary contracts by default
			is_ruler = yes
			vassal_contract_has_modifiable_obligations = yes
			government_has_flag = government_is_nomadic
		}
	}

	is_valid_showing_failures_only = {
		NOT = { scope:actor = { is_at_war_with = scope:recipient } }
	}

	can_send = {
		trigger_if = { #If they're blocked we don't want to show anything else
			limit = {
				scope:recipient = {
					subject_contract_is_blocked_from_modification = yes
				}
			}
			scope:recipient = {
				subject_contract_is_blocked_from_modification = no
			}
		}
		trigger_else = {
			scope:actor = {
				has_changed_contract_obligation_trigger = yes

				custom_description = {
					text = "liege_modify_vassal_contract_cannot_exceed_tyranny_cap"
					object = scope:actor
					NOT = {
						vassal_obligation_increase_tyranny_gain_multiplier > 1
					}
				}

				# Cannot change more than three things at once
				custom_description = {
					text = "vassal_modify_vassal_contract_obligation_change_limit"
					value = list_size:changed_obligations
					list_size:changed_obligations <= max_contract_changes
				}

				# If the trade without the hook usage is already in the vassal's favour or fair then don't waste your hook
				save_temporary_scope_value_as = {
					name = obligations_favoring_vassal
					value = scope:recipient.count_obligation_improvements_for_vassal
				}
				trigger_if = {
					limit = { scope:obligations_favoring_vassal > 0 }
					custom_description = {
						text = "vassal_modify_vassal_contract_unnecessary_hook_usage_vassal_favor"
						object = scope:recipient
						value = scope:obligations_favoring_vassal
						NOT = { always = scope:hook }
					}
				}
				trigger_else_if = {
					limit = { scope:obligations_favoring_vassal = 0 }
					custom_description = {
						text = "vassal_modify_vassal_contract_unnecessary_hook_usage_equal"
						object = scope:recipient
						NOT = { always = scope:hook }
					}
				}
				trigger_else = {} # Otherwise we're fine!
			}
		}
	}

	auto_accept = yes
	on_accept = {
		hidden_effect = {
			# Struggle Catalysts
			## We work these out first so they're not invalidated by the actual effect block.
			if = {
				limit = {
					catalyst_granted_powerful_diff_faith_vassal_religious_protection_preliminary_trigger = { CHAR = scope:recipient }
					scope:actor = {
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_granted_powerful_diff_faith_vassal_religious_protection
								CHAR = scope:recipient
							}
						}
					}
				}
				scope:actor = {
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_granted_powerful_diff_faith_vassal_religious_protection
								CHAR = scope:recipient
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_granted_powerful_diff_faith_vassal_religious_protection
							character = scope:actor
						}
					}
				}
			}
			if = {
				limit = {
					catalyst_revoked_powerful_diff_faith_vassal_religious_protection_preliminary_trigger = { CHAR = scope:recipient }
					scope:actor = {
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_revoked_powerful_diff_faith_vassal_religious_protection
								CHAR = scope:recipient
							}
						}
					}
				}
				scope:actor = {
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_revoked_powerful_diff_faith_vassal_religious_protection
								CHAR = scope:recipient
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_revoked_powerful_diff_faith_vassal_religious_protection
							character = scope:actor
						}
					}
				}
			}

			# Improving contract catalyst
			if = {
				limit = {
					scope:recipient.count_obligation_improvements_for_vassal > 0
					scope:actor = {
						is_diff_faith_or_culture_trigger = {
							CHAR = scope:recipient
							STATUS = involved
						}
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_grant_privilege_to_diff_faith_culture_vassal
								CHAR = scope:recipient
							}
						}
					}
				}
				scope:actor = {
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_grant_privilege_to_diff_faith_culture_vassal
								CHAR = scope:recipient
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_grant_privilege_to_diff_faith_culture_vassal
							character = scope:actor
						}
					}
				}
			}
		}

		# Enact changes.
		scope:actor = {
			send_interface_message = {
				type = msg_vassal_contract_change
				title = modify_vassal_contract_interaction_notification
				right_icon = scope:recipient
				if = {
					limit = { vassal_obligation_increase_tyranny_gain != 0 }
					stress_impact = {
						just = medium_stress_impact_gain
						generous = medium_stress_impact_gain
					}
				}
				if = {
					limit = {
						always = scope:hook
					}
					use_hook = scope:recipient
					add_achievement_flag_effect = { FLAG = achievement_fine_print_flag }
				}

				scope:recipient = {
					hidden_effect = {
						set_subject_contract_modification_blocked = yes
						set_variable = {
							name = vassal_modify_contract_cooldown
							value = yes
							years = vassal_modify_contract_cooldown_value
						}
					}
				}

				every_in_list = {
					list = changed_obligations

					save_scope_as = obligation

					scope:recipient = {
						vassal_contract_set_obligation_level = {
							type = scope:obligation.vassal_contract_type
							level = scope:obligation
						}
					}

				}
			}
		}

		# Additional Flavor Titles
		scope:recipient = { additional_flavor_check_effect = yes }
	}
	
	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
}

nomad_vassal_modify_vassal_contract_interaction = {
	special_interaction = vassal_modify_vassal_contract
	interface = modify_vassal_contract
	category = interaction_category_vassal
	interface_priority = 65
	common_interaction = yes
	icon = icon_contract_modification_single

	send_name = "nomad_vassal_modify_vassal_contract_interaction_send"
	desc = nomad_vassal_modify_vassal_contract_interaction_desc
	
	redirect = {
		# need to reverse the role for the UI to work properly
		scope:recipient = {
			save_scope_as = secondary_recipient
		}
		scope:actor = {
			save_scope_as = recipient
		}

		scope:secondary_recipient = {
			save_scope_as = actor
		}
	}

	is_shown = {
		scope:recipient = {
			is_independent_ruler = no
			NOT = { this = scope:actor }
			liege ?= scope:actor # this excludes tributary contracts by default
			vassal_contract_has_modifiable_obligations = yes
			government_has_flag = government_is_nomadic
		}
	}

	is_valid_showing_failures_only = {
		NOT = { scope:recipient = { is_at_war_with = scope:actor } }
	}

	can_send = {
		trigger_if = { #If you're blocked we don't want to show anything else
			limit = {
				scope:recipient = {
					subject_contract_is_blocked_from_modification = yes
				}
			}
			scope:recipient = {
				subject_contract_is_blocked_from_modification = no
			}
		}
		trigger_else = {
			# There is no cooldown present - To make sure we somehow don't show both cooldowns at the same time, we split them into separate triggers
			trigger_if = {
				limit = {
					scope:actor = {
						has_variable = vassal_modify_contract_cooldown
					}
				}
				custom_tooltip = {
					text = vassal_modify_contract_cooldown_desc
					scope:actor = {
						NOT = { has_variable = vassal_modify_contract_cooldown }
					}
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = nomad_contract_request_cooldown_desc
					scope:actor = {
						NOT = { has_variable = nomad_contract_request_cooldown }
					}
				}
			}
			scope:actor = {
				has_changed_contract_obligation_trigger = yes
			}

			scope:recipient = {
				# Must be an even trade overall
				custom_description = {
					text = "vassal_modify_vassal_contract_cannot_increase_obligation_level"
					object = scope:actor
					value = count_obligation_improvements_for_vassal_include_hook
					count_obligation_improvements_for_vassal_include_hook = 0
				}

				# Cannot change more than three things at once
				custom_description = {
					text = "vassal_modify_vassal_contract_obligation_change_limit"
					value = list_size:changed_obligations
					list_size:changed_obligations <= max_contract_changes
				}
			}
		}
	}

	auto_accept = yes

	on_accept = {
		# Enact changes
		scope:recipient = {
			send_interface_message = {
				type = msg_vassal_contract_change
				title = modify_vassal_contract_interaction_notification
				right_icon = scope:actor
				if = {
					limit = { always = scope:hook }
					use_hook = scope:actor
					add_achievement_flag_effect = { FLAG = achievement_fine_print_flag }
				}

				# Activate cooldown - To prevent liege from changing it too soon
				hidden_effect = {
					set_variable = {
						name = vassal_modify_contract_cooldown
						value = yes
						years = vassal_modify_contract_cooldown_value
					}
				}

				hidden_effect = { set_subject_contract_modification_blocked = yes }

				every_in_list = {
					list = changed_obligations

					save_scope_as = obligation

					scope:recipient = {
						vassal_contract_set_obligation_level = {
							type = scope:obligation.vassal_contract_type
							level = scope:obligation
						}
					}
				}
			}
		}
		# If there's a diarch involved, and they called in their change, that gets flagged.
		diarch_changed_own_contract_effect = yes
		# Additional Flavor Titles
		scope:recipient = { additional_flavor_check_effect = yes }
	}

	on_decline = {
		# Activate cooldown - You may only ask for it to be changed every so often (this mostly exists for MP, since you cannot send it to the AI unless they accept)
		hidden_effect = {
			scope:recipient = {
				set_variable = {
					name = nomad_contract_request_cooldown
					value = yes
					years = vassal_modify_contract_cooldown_value
				}
			}
		}
	}

	# Send Options
	# Hook
	send_option = {
		is_valid = {
			scope:recipient = {
				has_usable_hook = scope:actor
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	send_option = {
		is_shown = {
			scope:recipient = { is_diarch_of_target = scope:actor }
		}
		is_valid = {
			scope:recipient = {
				trigger_if = {
					limit = { has_variable_list = diarch_contract_rights_used_list }
					NOT = {
						is_target_in_variable_list = {
							name = diarch_contract_rights_used_list
							target = scope:actor
						}
					}
				}
			}
		}
		flag = diarch
		localization = CALL_IN_DIARCH_RIGHTS
	}
	should_use_extra_icon = {
		scope:recipient = { has_usable_hook = scope:actor }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"
	send_options_exclusive = no
}

suzerain_modify_tributary_contract_interaction = {
	special_interaction = liege_modify_vassal_contract
	interface = modify_vassal_contract
	category = interaction_category_vassal
	common_interaction = yes
	icon = icon_contract_modification_single

	send_name = "suzerain_modify_tributary_contract_interaction_send"
	desc = suzerain_modify_tributary_contract_interaction_desc

	force_notification = yes
	notification_text = MODIFY_VASSAL_CONTRACT_NOTIFICATION_TO_VASSAL

	is_shown = {
		scope:recipient = {
			is_tributary_of = scope:actor # excludes vassals by default
			subject_contract_has_modifiable_obligations = yes
			NOT = { government_has_flag = government_is_true_herder }
		}
	}

	is_valid_showing_failures_only = {
		NOT = { scope:recipient = { is_at_war_with = scope:actor } }
	}

	can_send = {
		#Mandala gets special treatment
		trigger_if = {
			limit = { 
				scope:actor = { government_has_flag = government_is_mandala }
			}
			custom_tooltip = {
				text = suzerain_modify_subject_contract_mandala_cooldown
				NOT = {
					scope:recipient = { var:suzerain_recently_adjusted_mandala_subject_contract ?= scope:actor }
				}
			}
			scope:actor = {
				has_changed_contract_obligation_trigger = yes

				# Cannot change more than three things at once
				custom_description = {
					text = "vassal_modify_vassal_contract_obligation_change_limit"
					value = list_size:changed_obligations
					list_size:changed_obligations <= max_contract_changes
				}

				# If the trade without the hook usage is already in the vassal's favour or fair then don't waste your hook
				save_temporary_scope_value_as = {
					name = obligations_favoring_tributary
					value = scope:recipient.count_obligation_improvements_for_vassal
				}
				trigger_if = {
					limit = { scope:obligations_favoring_tributary > 0 }
					custom_description = {
						text = "tributary_modify_vassal_contract_unnecessary_hook_usage_vassal_favor"
						object = scope:recipient
						value = scope:obligations_favoring_tributary
						NOT = { always = scope:hook }
					}
				}
				trigger_else_if = {
					limit = { scope:obligations_favoring_tributary = 0 }
					custom_description = {
						text = "tributary_modify_vassal_contract_unnecessary_hook_usage_equal"
						object = scope:recipient
						NOT = { always = scope:hook }
					}
				}

				# You can afford the prestige cost of an unequal contract
				trigger_else_if = {
					limit = {
						scope:obligations_favoring_tributary < 0
						NOT = { always = scope:hook }
					}
					scope:actor = { piety >= major_piety_value }
				}
				trigger_else = {} # Otherwise we're fine!
			}
		}
		trigger_else_if = { #If they're blocked we don't want to show anything else
			limit = {
				scope:recipient = {
					subject_contract_is_blocked_from_modification = yes
				}
			}
			scope:recipient = {
				subject_contract_is_blocked_from_modification = no
			}
		}
		trigger_else = {
			scope:actor = {
				has_changed_contract_obligation_trigger = yes

				# Cannot change more than three things at once
				custom_description = {
					text = "vassal_modify_vassal_contract_obligation_change_limit"
					value = list_size:changed_obligations
					list_size:changed_obligations <= max_contract_changes
				}

				# If the trade without the hook usage is already in the vassal's favour or fair then don't waste your hook
				save_temporary_scope_value_as = {
					name = obligations_favoring_tributary
					value = scope:recipient.count_obligation_improvements_for_vassal
				}
				trigger_if = {
					limit = { scope:obligations_favoring_tributary > 0 }
					custom_description = {
						text = "tributary_modify_vassal_contract_unnecessary_hook_usage_vassal_favor"
						object = scope:recipient
						value = scope:obligations_favoring_tributary
						NOT = { always = scope:hook }
					}
				}
				trigger_else_if = {
					limit = { scope:obligations_favoring_tributary = 0 }
					custom_description = {
						text = "tributary_modify_vassal_contract_unnecessary_hook_usage_equal"
						object = scope:recipient
						NOT = { always = scope:hook }
					}
				}

				# You can afford the prestige cost of an unequal contract
				trigger_else_if = {
					limit = {
						scope:obligations_favoring_tributary < 0
						NOT = { always = scope:hook }
					}
					scope:actor = {
						prestige >= medium_prestige_value
					}
				}
				trigger_else = {} # Otherwise we're fine!
			}
		}
	}

	auto_accept = yes

	on_accept = {
		scope:actor = {
			send_interface_message = {
				type = msg_vassal_contract_change
				title = modify_vassal_contract_interaction_notification
				right_icon = scope:recipient
				if = {
					limit = {
						always = scope:hook
					}
					use_hook = scope:recipient
					add_achievement_flag_effect = { FLAG = achievement_fine_print_flag }
				}

				# Prestige and opinion cost of making an unequal contract without a hook
				if = {
					limit = {
						scope:recipient.count_obligation_improvements_for_vassal < 0
						NOT = { always = scope:hook }
					}

					if = {
						limit = { government_has_flag = government_is_mandala }
						add_piety = major_piety_loss
					}
					else = { add_prestige = medium_prestige_loss }
					
					scope:recipient = {
						add_opinion = {
							modifier = outraged_opinion
							opinion = -30
							target = scope:actor
						}
					}

					every_tributary = {
						limit = {
							NOT = { this = scope:recipient }
						}
						add_opinion = {
							modifier = outraged_opinion
							opinion = -10
							target = scope:actor
						}
					}
				}

				scope:recipient = {
					hidden_effect = {
						set_subject_contract_modification_blocked = yes
					}
					set_variable = {
						name = suzerain_recently_adjusted_mandala_subject_contract
						value = scope:actor
						years = mandala_vassal_obligation_cooldown_years
					}
				}

				every_in_list = {
					list = changed_obligations

					save_scope_as = obligation

					scope:recipient = {
						tributary_contract_set_obligation_level = {
							type = scope:obligation.vassal_contract_type
							level = scope:obligation
						}
					}
				}
			}
		}

		# Additional Flavor Titles
		scope:recipient = { additional_flavor_check_effect = yes }
	}

	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
}

subject_modify_tributary_contract_interaction = {
	special_interaction = vassal_modify_vassal_contract
	interface = modify_vassal_contract
	category = interaction_category_vassal
	interface_priority = 65
	common_interaction = yes
	icon = icon_contract_modification_single

	send_name = "subject_modify_tributary_contract_interaction_send"
	desc = subject_modify_tributary_contract_interaction_desc

	is_shown = {
		scope:actor = {
			is_tributary_of = scope:recipient # excludes vassals by default
			subject_contract_has_modifiable_obligations = yes
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_travelling = no
		}
		NOT = { scope:recipient = { is_at_war_with = scope:actor } }
	}

	can_send = {
		#Mandala gets special treatment
		trigger_if = {
			limit = { 
				scope:recipient = { government_has_flag = government_is_mandala }
			}
			custom_tooltip = {
				text = subject_modify_subject_contract_mandala_cooldown
				NOT = {
					scope:actor = { var:subject_recently_adjusted_mandala_subject_contract ?= scope:recipient }
				}
			}
			# You can afford the cost if there is one
			scope:actor = {
				has_changed_contract_obligation_trigger = yes
				trigger_if = {
					limit = { scope:hook = no } # no cost
					trigger_if = {
						limit = { subject_standing < 0 } # this means we don't use subject standing	
						trigger_if = {
							limit = { 
								government_has_flag = government_is_nomadic
								scope:recipient = { government_has_flag = government_is_nomadic }
							}
							domicile.herd >= domicile.major_herd_value
						}
						trigger_else = {
							gold >= major_gold_value
						}
					}
					trigger_else = {
						subject_standing > 20
					}
				}
			}
		}
		trigger_else_if = { #If you're blocked we don't want to show anything else (we don't really use this for admin, but we'll keep the logic, just in case)
			limit = {
				scope:actor = {
					subject_contract_is_blocked_from_modification = yes
				}
			}
			scope:actor = {
				subject_contract_is_blocked_from_modification = no
			}
		}
		trigger_else = {
			# There is no cooldown present - To make sure we somehow don't show both cooldowns at the same time, we split them into separate triggers
			trigger_if = {
				limit = {
					scope:actor = {
						has_variable = tributary_modify_contract_cooldown
					}
				}
				custom_tooltip = {
					text = tributary_modify_contract_cooldown_desc
					scope:actor = {
						NOT = { has_variable = tributary_modify_contract_cooldown }
					}
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = tributary_modify_contract_cooldown_desc
					scope:actor = {
						NOT = { has_variable = tributary_modify_contract_cooldown }
					}
				}
			}

			# You can afford the cost if there is one
			scope:actor = {
				trigger_if = {
					limit = { scope:hook = no } # no cost
					trigger_if = {
						limit = { subject_standing < 0 } # this means we don't use subject standing	
						trigger_if = {
							limit = { 
								government_has_flag = government_is_nomadic
								scope:recipient = { government_has_flag = government_is_nomadic }
							}
							domicile.herd >= domicile.major_herd_value
						}
						trigger_else = {
							gold >= major_gold_value
						}
					}
					trigger_else = {
						subject_standing > 20
					}
				}
			}
		}
	}

	auto_accept = {
		custom_tooltip = {
			text = nomad_vassal_force_obligation_change_desc
			scope:hook = yes
		}
	}

	on_accept = {
		# Enact changes
		scope:actor = {
			send_interface_message = {
				type = msg_vassal_contract_change
				title = modify_vassal_contract_interaction_notification
				right_icon = scope:recipient

				# If you use a hook - Spend it
				if = {
					limit = { always = scope:hook }
					use_hook = scope:recipient
				}
				else = {
					if = {
						limit = { subject_standing < 0 } # this means we don't use subject standing	
						if = {
							limit = { 
								government_has_flag = government_is_nomadic
								scope:recipient = { government_has_flag = government_is_nomadic }
							}
							pay_herd = {
								target = scope:recipient
								value = domicile.major_herd_value
							}
						}
						else = {
							pay_short_term_gold = {
								target = scope:recipient
								gold = major_gold_value
							}
						}
					}
					else = {
						if = { # the subject tilting the contract in their favor costs Subject Standing
							limit = { scope:new_value < 0 }
							add_subject_standing = {
								value = 10
								multiply = scope:new_value
							}
						}
					}
				}

				# Activate cooldown - To prevent liege from changing it too soon
				hidden_effect = {
					set_variable = {
						name = tributary_modify_contract_cooldown
						value = yes
						years = tributary_modify_contract_cooldown_value
					}
				}
				set_variable = {
					name = subject_recently_adjusted_mandala_subject_contract
					value = scope:recipient
					years = mandala_vassal_obligation_cooldown_years
				}

				every_in_list = {
					list = changed_obligations

					save_scope_as = obligation

					scope:actor = {
						tributary_contract_set_obligation_level = {
							type = scope:obligation.subject_contract_type
							level = scope:obligation
						}
					}
				}
			}
		}

		# If there's a diarch involved, and they called in their change, that gets flagged.
		diarch_changed_own_contract_effect = yes
	}

	on_decline = {
		# Activate cooldown - You may only ask for it to be changed every so often (this mostly exists for MP, since you cannot send it to the AI unless they accept)
		hidden_effect = {
			scope:actor = {
				set_variable = {
					name = tributary_modify_contract_cooldown
					value = yes
					years = tributary_modify_contract_cooldown_value
				}
			}
		}
	}

	# Send Options
	# Hook
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	send_option = {
		is_shown = {
			scope:actor = { is_diarch_of_target = scope:recipient }
		}
		is_valid = {
			scope:actor = {
				trigger_if = {
					limit = { has_variable_list = diarch_contract_rights_used_list }
					NOT = {
						is_target_in_variable_list = {
							name = diarch_contract_rights_used_list
							target = scope:recipient
						}
					}
				}
			}
		}
		flag = diarch
		localization = CALL_IN_DIARCH_RIGHTS
	}
	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_accept = {
		base = -25

		# Opinion Factor
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1
			desc = AI_OPINION_REASON
		}

		modifier = {
			add = {
				add = scope:new_value
				multiply = -20 #Overlord favoring options have a negative score
				if = { # the Chinese Emperor cares less since they get tribute through missions as well
					limit = { 
						scope:new_value < 0
						scope:actor = { 
							OR = {
								has_subject_contract_group = tributary_celestial
								has_subject_contract_group = tributary_hegemonic
							}
						} 
					}
					multiply = 0.5
				}
			}
			desc = AI_CONTRACT_BALANCE
		}
	}
}

ai_only_hegemonic_tributary_modify_tributary_contract_interaction = {
	category = interaction_category_vassal
	desc = subject_modify_tributary_contract_interaction_desc

	auto_accept = yes

	is_shown = {
		scope:actor = {
			is_ai = yes
			is_available = yes # Let's not have the AI do this when they're away from home etc (like paying tribute)
			is_tributary_of = scope:recipient # excludes vassals by default
			OR = {
				has_subject_contract_group = tributary_celestial
				has_subject_contract_group = tributary_hegemonic
			}
			subject_standing > 40
			subject_contract_has_modifiable_obligations = yes
			does_ai_subject_in_subject_contract_desire_obligation_change = yes
			NOT = { is_at_war_with = scope:recipient }
		}
	}

	on_accept = {
		scope:actor = {
			if = {
				# if the subject has a Seal of Investiture, they will always ask for an Investiture Privilege if they can
				limit = { 
					any_character_artifact = {
						OR = {
							artifact_type = seal_of_investiture
							artifact_type = seal_of_investiture_court
						}
					}
				}
				random_list = {
					33 = {
						trigger = {
							tributary_contract_obligation_level_can_be_increased = celestial_tributary_investiture_privilege_trade
						}
						save_scope_value_as = { name = ask value = flag:trade }
					}
					33 = {
						trigger = {
							tributary_contract_obligation_level_can_be_increased = celestial_tributary_investiture_privilege_marriage
						}
						save_scope_value_as = { name = ask value = flag:marriage }
					}
					33 = {
						trigger = {
							tributary_contract_obligation_level_can_be_increased = celestial_tributary_investiture_privilege_politics
						}
						save_scope_value_as = { name = ask value = flag:politics }
					}
				}
			}
			suzerain = {
				trigger_event = char_interaction.0252
			}
		}
	}

	ai_potential = {
		always = yes
	}

	ai_targets = {
		ai_recipients = suzerain
	}

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

	ai_will_do = {
		base = 100
	}
}
