﻿gpt_retract_vassal_interaction = {
	category = interaction_category_vassal
	special_interaction = retract_vassal_interaction
	interface = transfer_vassal
	ai_maybe = yes
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	popup_on_receive = yes
	pause_on_receive = yes
	icon = icon_liege

	desc = retract_vassal_interaction_desc

	on_decline_summary = general_rebellion_decline_summary

	prompt = RETRACT_VASSAL_SELECT_VASSAL_TO_RETRACT

	notification_text = RETRACT_VASSAL_PROPOSAL

	populate_recipient_list = {
		scope:recipient = {
			every_vassal = {
				add_to_list = characters
			}
		}
	}

	is_shown = {
		scope:actor = { 
			is_ai = yes
			sub_realm_size >= 16
			vassal_count < vassal_limit
		}
		NOT = { scope:recipient = scope:actor }
		scope:recipient = {
			is_ai = yes
			highest_held_title_tier > tier_barony
			liege = scope:actor
		}
	}

	is_valid_showing_failures_only = {
		vassal_retraction_standard_valid_showing_failures_only_trigger = yes
		# Make sure this exactly matches "can_be_picked" section below
		scope:recipient = {
			custom_description = {
				text = "basic_vassal_to_retract"
				any_vassal = {
					highest_held_title_tier > tier_barony
					is_ai = yes
					NOT = {
						any_held_title = {
							any_this_title_or_de_jure_above = { this = scope:recipient.primary_title }
						}
					}
				}
			}
			sub_realm_size >= {
				value = scope:actor.sub_realm_size
				divide = 3
			}
		}
		# Plus make sure there's a legal right to retract.
		scope:actor = {
			trigger_if = {
				limit = {
					government_has_flag = government_is_tribal
				}
				custom_description = {
					text = "has_law_allowing_vassal_retraction_tribal"
					has_realm_law_flag = vassal_retraction_allowed
				}
			}
			trigger_else_if = {
				limit = {
					government_has_flag = government_is_administrative
				}
				custom_description = {
					text = "has_law_allowing_vassal_retraction_admin"
					has_realm_law_flag = vassal_retraction_allowed
				}
			}
			trigger_else = {
				custom_description = {
					text = "has_law_allowing_vassal_retraction_crown"
					has_realm_law_flag = vassal_retraction_allowed
				}
			}
		}
		scope:recipient = { basic_is_available_ai = yes }
		trigger_if = {
			limit = { exists = scope:secondary_recipient }
			scope:secondary_recipient = { basic_is_available_ai = yes }
		}
		scope:recipient = {
			NOT = { has_strong_hook = scope:actor }
		}
		custom_tooltip = {
			text = cannot_take_overt_hostile_actions_against_diarch.tt
			NOT = { scope:recipient ?= scope:actor.diarch }
		}
	}

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
	}

	can_be_picked = {
		highest_held_title_tier > tier_barony
		is_ai = yes
		NOT = {
			any_held_title = {
				any_this_title_or_de_jure_above = { this = scope:recipient.primary_title }
			}
		}
	}

	cost = {
		# Usually, this action is free, but during certain diarchies, we want it to cost.
		prestige = liege_diarchy_surcharge_interaction_retract_vassal_interaction_value
	}

	on_send = {
		scope:actor = {
			add_character_flag = {
				flag = flag_hostile_actions_disabled_delay
				days = 10
			}
		}
		hidden_effect = {
			scope:secondary_recipient = {
				add_character_flag = {
					flag = ai_should_not_transfer
					years = 3
				}
			}
		}
	}

	on_accept = {
		retract_vassal_interaction_effect = yes

		if = {
			limit = {
				scope:actor = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
			scope:actor = { remove_character_flag = flag_hostile_actions_disabled_delay }
		}

		scope:actor = {
			trigger_event = char_interaction.0220
		}
	}

	on_decline = {
		scope:actor = { vassal_revocation_tyranny_effect = yes }
		war_for_retraction_effect = yes
		scope:recipient = {
			add_opinion = {
				target = scope:actor
				modifier = retracted_vassal
			}
		}
		if = {
			limit = {
				scope:actor = { has_realm_law_flag = vassal_refusal_is_treason }
			}
			scope:actor = {
				add_opinion = {
					target = scope:recipient
					modifier = treasonous_retract_refusal
				}
			}
		}
		if = {
			limit = {
				scope:actor = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
			scope:actor = { remove_character_flag = flag_hostile_actions_disabled_delay }
		}
	}

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

	can_be_blocked = {
		custom_description = { #Hook from Recipient can counteract, but only if Actor is not forcing the action via Strong Hook.
			text = "spending_hook"
			subject = scope:recipient
			object = scope:actor
			scope:recipient = { has_hook = scope:actor }
			NAND = {
				scope:hook = yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
		}
	}

	on_blocked_effect = {
		scope:recipient = {
			remove_hook = {
				target = scope:actor
			}
		}
	}

	ai_accept = {
		base = 100
	}

	#Use hook
	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

	can_send_despite_rejection = yes

	# AI
	ai_targets = {
		ai_recipients = vassals
	}
	ai_frequency = 12

	ai_potential = {
		has_realm_law_flag = title_revocation_allowed
		primary_title.tier > tier_county
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = 100
			scope:actor = {
				tyranny <= 20
			}
		}
	}
}