# Pick a favorite child to pre-select when choosing your destiny
choose_favorite_interaction = {
	category = interaction_category_friendly
	icon = designate_favorite
	interface_priority = 8

	desc = choose_favorite_interaction_desc

	is_shown = {
		scope:actor = { 
			is_ai = no 
			NOT = { has_relation_favorite_child = scope:recipient }
		}
		scope:recipient.dynasty = scope:actor.dynasty
		NOT = { scope:actor = scope:recipient }
		scope:recipient = {
			OR = {
				is_child_of = scope:actor
				is_grandchild_of = scope:actor
				is_great_grandchild_of = scope:actor
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = { is_alive = yes }
		scope:recipient = {
			custom_tooltip = {
				text = cant_be_another_player_tt
				is_ai = yes
			}
			custom_tooltip = {
				text = favorite_child_must_be_in_good_health_tt
				NOR = {
					has_trait = incapable
					health <= 2.5
				}
			}
			custom_tooltip = {
				text = cant_be_hostage_tt
				is_hostage = no
			}
			custom_tooltip = {
				text = cant_already_be_your_heir
				NOT = {
					this = scope:actor.player_heir
				}
			}
			custom_tooltip = {
				text = no_republic_or_theocracy_tt
				NOR = {
					government_has_flag = government_is_republic
					government_has_flag = government_is_theocracy
				}
			}
			trigger_if = {
				limit = {
					is_ruler = yes
				}
				custom_tooltip = {
					text = not_baron_holy_order_merc_tt
					highest_held_title_tier >= tier_county
					primary_title = {
						is_mercenary_company = no
						is_holy_order = no
					}
				}
			}
		}
	}

	on_auto_accept = {
		scope:recipient = {
			send_interface_message = {
				title = choose_favorite_interaction_notification
				left_icon = scope:actor
				show_as_tooltip = {
					scope:actor = {
						set_relation_favorite_child = { reason = favorite_child_chosen target = scope:recipient }
					}
				}
			}
		}
	}

	on_accept = {
		assign_favourite_child_effect = {
			ACTOR = scope:actor
			RECIPIENT = scope:recipient
		}
	}

	auto_accept = yes
}

remove_favorite_interaction = {
	category = interaction_category_friendly
	icon = designate_favorite
	interface_priority = 7

	desc = remove_favorite_interaction_desc

	is_shown = {
		scope:actor = { 
			is_alive = yes 
			has_relation_favorite_child = scope:recipient 
		}
	}

	on_auto_accept = {
		scope:recipient = {
			send_interface_message = {
				title = remove_favorite_interaction_notification
				left_icon = scope:actor
				show_as_tooltip = {
					scope:actor = {
						remove_relation_favorite_child = scope:recipient
					}
				}
			}
		}
	}

	on_accept = {
		scope:actor = {
			random_relation = {
				type = favorite_child
				save_scope_as = current_favorite
			}
			send_interface_toast = {
				title = remove_favorite_interaction_notification
				left_icon = scope:actor					
				right_icon = scope:recipient
				if = {
					limit = {
						exists = scope:current_favorite
					}
					remove_relation_favorite_child = scope:current_favorite
					scope:current_favorite = {
						add_opinion = {
							target = scope:actor
							modifier = no_more_favorite_opinion
						}
					}
				}
				custom_tooltip = remove_favorite_interaction_notification.tt
			}
			hidden_effect = {
				every_close_or_extended_family_member = {
					limit = {
						is_child_of = scope:actor
						is_grandchild_of = scope:actor
						is_great_grandchild_of = scope:actor
					}
					add_opinion = {
						target = scope:actor
						modifier = no_more_favorite_opinion
					}
					add_opinion = {
						target = scope:recipient
						modifier = no_more_favorite_opinion
					}
				}
			} 
		}		
	}

	auto_accept = yes
}
