# change_council_job_potential_trigger
# can_be_chancellor_trigger
# can_be_marshal_trigger
# can_be_treasurer_trigger
# can_be_spymaster_trigger
# can_be_spiritual_trigger
# can_be_councilmember_king_trigger
# can_be_councilmember_emperor_trigger

# ere_elective_politician_titles_trigger
# can_still_be_commander_byzantine_trigger
# can_still_be_marshal_byzantine_trigger
# byzantines_can_grant_commander_trigger

### Council Jobs ###

# Used with character interaction to swap council job. DO NOT REMOVE
# ROOT is councillor
# FROM is liege
change_council_job_potential_trigger = {
	liege = {
		character = FROM
		NOT = { has_law = council_privileges_1 } # Lifetime Appointment
	}

	trigger_if = {
		limit = {
			has_job_title = job_spiritual
			liege = { religion_group = muslim }
		}

		NOT = { religion = FROM }
	}

	# Only used to move councillors to an empty council spot,
	# see switch_council_job in zz_CK2Plus_minor_decisions.txt for switching two councillors
	OR = {
		AND = {
			liege = { NOT = { job_chancellor = { always = yes } } }
			can_be_chancellor_trigger = yes
		}

		AND = {
			liege = { NOT = { job_marshal = { always = yes } } }
			can_be_marshal_trigger = yes
		}

		AND = {
			liege = { NOT = { job_treasurer = { always = yes } } }
			can_be_treasurer_trigger = yes
		}

		AND = {
			liege = { NOT = { job_spymaster = { always = yes } } }
			can_be_spymaster_trigger = yes
		}

		AND = {
			liege = { NOT = { job_spiritual = { always = yes } } }
			can_be_spiritual_trigger = yes
		}

		AND = {
			liege = { can_grant_title = title_councilmember_king }
			can_be_councilmember_king_trigger = yes
		}

		AND = {
			liege = { can_grant_title = title_councilmember_emperor }
			can_be_councilmember_emperor_trigger = yes
		}
	}
}

# THIS is potential councillor
can_be_chancellor_trigger = {
	independent = no
	prisoner = no
	is_incapable = no

	NOR = {
		trait = in_hiding
		has_character_modifier = resigned_in_anger
		has_character_modifier = planning_claimant_adventure

		reverse_has_opinion_modifier = {
			name = opinion_resigned_from_council
			who = liege
		}
	}

	trigger_if = {
		limit = { NOT = { has_character_flag = special_chancellor } }

		is_adult = yes

		trigger_if = {
			limit = { religion = waldensian }

			OR = {
				is_theocracy = no
				is_ruler = no
			}
		}

		trigger_if = {
			limit = {
				religion = bogomilist

				OR = {
					trait = perfecti
					is_theocracy = yes
				}
			}

			liege = {
				religion = bogomilist

				OR = {
					has_law = bogomilist_church_2
					has_law = bogomilist_church_3
					has_law = bogomilist_church_4
				}
			}
		}

		trigger_if = {
			limit = {
				NOT = { trait = horse }
			}

			trigger_if = {
				limit = { is_female = yes }

				liege = {
					OR = {
						has_religion_feature = religion_matriarchal
						has_religion_feature = religion_equal
						has_religion_feature = religion_feature_bon

						# Some religions don't mind so much who does what
						trigger_if = {
							limit = {
								OR = {
									religion = cathar
									religion = messalian
								}
							}

							religion = PREV
						}

						# Laws permitting
						trigger_if = {
							limit = {
								OR = {
									has_law = status_of_women_2
									has_law = status_of_women_3
								}
							}

							PREV = {
								OR = {
									dynasty = PREV
									is_close_relative = PREV
									is_married = PREV
									is_consort = PREV
									is_landed = yes
									trait = nun
									trait = desert_mother
									trait = perfecti
								}
							}
						}
						trigger_else = {
							has_law = status_of_women_4
						}

						# Other conditions under which females can be employed
						has_gender_equal_game_rule_trigger = yes
					}
				}
			}
			trigger_else = {
				liege = {
					NOT = { has_religion_feature = religion_matriarchal }
				}
			}
		}
	}
}

can_be_marshal_trigger = {
	independent = no
	prisoner = no
	is_incapable = no

	NOR = {
		trait = in_hiding
		has_character_modifier = resigned_in_anger
		has_character_modifier = planning_claimant_adventure

		reverse_has_opinion_modifier = {
			name = opinion_resigned_from_council
			who = liege
		}
	}

	trigger_if = {
		limit = { NOT = { has_character_flag = special_marshal } }

		is_adult = yes

		NOR = {
			trait = desert_father
			trait = desert_mother
			trait = pf_neutral
			has_character_flag = guru
		}

		trigger_if = {
			limit = { religion = hindu }
			trait = kshatriya
		}
		trigger_else_if = {
			limit = {
				religion = bogomilist

				OR = {
					is_theocracy = yes
					trait = perfecti
				}
			}

			liege = {
				religion = bogomilist

				OR = {
					has_law = bogomilist_church_2
					has_law = bogomilist_church_3
					has_law = bogomilist_church_4
				}
			}
		}

		trigger_if = {
			limit = {
				controls_religion = yes
				ai = yes
			}
			has_called_crusade = no
		}

		trigger_if = {
			limit = {
				NOT = { trait = horse }
			}

			trigger_if = {
				limit = { is_female = yes }

				liege = {
					OR = {
						has_religion_feature = religion_matriarchal
						has_religion_feature = religion_equal
						has_religion_feature = religion_feature_bon

						# Some religions don't mind so much who does what
						trigger_if = {
							limit = { is_feminist_trigger = yes }
							PREV = { is_feminist_trigger = yes }
						}
						trigger_else_if = {
							limit = { religion_openly_norse_or_reformed_trigger = yes }
							religion = PREV
						}
						trigger_else_if = {
							limit = {
								culture_group = iranian
								religion_group = zoroastrian_group
							}

							PREV = {
								culture_group = iranian
								religion_group = zoroastrian_group
								any_dynasty_member = { higher_real_tier_than = BARON }
							}
						}

						# Laws permitting
						trigger_if = {
							limit = { has_law = status_of_women_3 }

							PREV = {
								OR = {
									dynasty = PREV
									is_close_relative = PREV
									is_married = PREV
									is_consort = PREV
									is_landed = yes
									trait = nun
								}
							}
						}
						trigger_else = {
							has_law = status_of_women_4
						}

						# Other conditions under which females can be employed
						has_gender_equal_game_rule_trigger = yes

						PREV = {
							OR = {
								trait = martial_lady
								trait = martial_lady_tengri
								trait = martial_lady_pagan
							}
						}
					}
				}
			}
			trigger_else = {
				liege = {
					NOT = { has_religion_feature = religion_matriarchal }
				}
			}
		}
	}
}

can_be_treasurer_trigger = {
	independent = no
	prisoner = no
	is_incapable = no

	NOR = {
		trait = in_hiding
		has_character_modifier = resigned_in_anger
		has_character_modifier = planning_claimant_adventure

		reverse_has_opinion_modifier = {
			name = opinion_resigned_from_council
			who = liege
		}
	}

	trigger_if = {
		limit = { NOT = { has_character_flag = special_treasurer } }

		is_adult = yes

		NOR = {
			trait = desert_father
			trait = desert_mother
			has_character_flag = guru
		}

		trigger_if = {
			limit = { religion = waldensian }

			OR = {
				is_theocracy = no
				is_ruler = no
			}
		}
		trigger_else_if = {
			limit = {
				religion = bogomilist

				OR = {
					is_theocracy = yes
					trait = perfecti
				}
			}

			liege = {
				religion = bogomilist

				OR = {
					has_law = bogomilist_church_2
					has_law = bogomilist_church_3
					has_law = bogomilist_church_4
				}
			}
		}

		trigger_if = {
			limit = {
				NOT = { trait = horse }
			}

			trigger_if = {
				limit = { is_female = yes }

				liege = {
					OR = {
						has_religion_feature = religion_matriarchal
						has_religion_feature = religion_equal
						has_religion_feature = religion_feature_bon

						# Some religions don't mind so much who does what
						trigger_if = {
							limit = { is_feminist_trigger = yes }
							PREV = { is_feminist_trigger = yes }
						}

						# Laws permitting
						trigger_if = {
							limit = {
								OR = {
									has_law = status_of_women_2
									has_law = status_of_women_3
								}
							}

							PREV = {
								OR = {
									dynasty = PREV
									is_close_relative = PREV
									is_married = PREV
									is_consort = PREV
									is_landed = yes
									trait = nun
									trait = perfecti
								}
							}
						}
						trigger_else = {
							has_law = status_of_women_4
						}

						# Other conditions under which females can be employed
						has_gender_equal_game_rule_trigger = yes
						is_close_relative = PREV
						is_married = PREV
					}
				}
			}
			trigger_else = {
				liege = {
					NOT = { has_religion_feature = religion_matriarchal }
				}
			}
		}
	}
}

can_be_spymaster_trigger = {
	independent = no
	prisoner = no
	is_incapable = no

	NOR = {
		trait = in_hiding
		has_character_modifier = resigned_in_anger
		has_character_modifier = planning_claimant_adventure

		reverse_has_opinion_modifier = {
			name = opinion_resigned_from_council
			who = liege
		}
	}

	trigger_if = {
		limit = { NOT = { has_character_flag = special_spymaster } }

		is_adult = yes

		NOR = {
			trait = desert_father
			trait = desert_mother
			has_character_flag = guru
		}

		trigger_if = {
			limit = {
				religion = bogomilist

				OR = {
					is_theocracy = yes
					trait = perfecti
				}
			}

			liege = {
				religion = bogomilist

				OR = {
					has_law = bogomilist_church_2
					has_law = bogomilist_church_3
					has_law = bogomilist_church_4
				}
			}
		}

		trigger_if = {
			limit = {
				NOT = { trait = horse }
			}

			trigger_if = {
				limit = { is_female = yes }

				liege = {
					OR = {
						# Special conditions for spymaster position
						is_married = PREV
						is_mother = PREV

						# Religious views
						has_religion_feature = religion_matriarchal
						has_religion_feature = religion_equal
						has_religion_feature = religion_feature_bon

						# Some religions don't mind so much who does what
						trigger_if = {
							limit = { is_feminist_trigger = yes }
							PREV = { is_feminist_trigger = yes }
						}
						trigger_else_if = {
							limit = {
								religion_group = pagan_group
								NOT = { has_religion_feature = religion_patriarchal }
							}
							PREV = { religion_group = pagan_group }
						}

						# Laws permitting
						trigger_if = {
							limit = {
								OR = {
									has_law = status_of_women_1
									has_law = status_of_women_2
									has_law = status_of_women_3
								}
							}

							PREV = {
								OR = {
									dynasty = PREV
									is_close_relative = PREV
									is_married = PREV
									is_consort = PREV
									is_landed = yes
									trait = nun
								}
							}
						}
						trigger_else = {
							has_law = status_of_women_4
						}

						# Other conditions under which females can be employed
						has_gender_equal_game_rule_trigger = yes
					}

					NOT = { has_religion_feature = religion_patriarchal }
				}
			}
			trigger_else = {
				liege = {
					NOT = { has_religion_feature = religion_matriarchal }
				}
			}

			OR = {
				intrigue >= 10
				has_education_intrigue_trigger = yes
			}
		}
	}
}

can_be_spiritual_trigger = {
	religion = liege
	independent = no
	prisoner = no
	is_incapable = no

	NOR = {
		trait = in_hiding
		has_character_modifier = resigned_in_anger
		has_character_modifier = planning_claimant_adventure

		reverse_has_opinion_modifier = {
			name = opinion_resigned_from_council
			who = liege
		}
	}

	trigger_if = {
		limit = { NOT = { has_character_flag = special_spiritual } }

		is_adult = yes

		trigger_if = {
			limit = { is_female = yes }

			OR = {
				religion_allows_female_temple_holders = yes
				has_religion_feature = religion_matriarchal
			}
		}
		trigger_else = {
			OR = {
				religion_allows_male_temple_holders = yes
				has_religion_feature = religion_patriarchal
			}
		}

		trigger_if = {
			limit = { religion = hindu }

			OR = {
				trait = brahmin
				is_ascetic_trigger = yes
			}
		}
		trigger_else_if = {
			limit = { religion_group = muslim }

			OR = {
				has_education_learning_trigger = yes
				trait = druze_uqqal
				trait = druze_ajawid
			}
		}
		trigger_else_if = {
			limit = {
				religion = bogomilist

				OR = {
					is_theocracy = yes
					trait = perfecti
				}
			}

			liege = {
				OR = {
					has_law = bogomilist_church_3
					has_law = bogomilist_church_4
				}
			}
		}

		trigger_if = {
			limit = {
				is_theocracy = no
				is_ascetic_trigger = no
				NOT = { religion_group = muslim }
			}

			OR = {
				AND = {
					has_education_learning_trigger = yes
					is_ruler = no
					has_autocephaly = no
				}

				religion = lollard
				trait = desert_father
				trait = desert_mother
				trait = perfecti

				trigger_if = {
					limit = { clan = yes }
					liege = { is_nomadic = yes }
				}
				trigger_else_if = {
					limit = {
						liege = {
							has_autocephaly = yes
							is_tribal = no

							OR = {
								any_vassal = {
									is_theocracy = yes
									is_voter = no
								}

								job_spiritual = { is_theocracy = yes }
							}
						}
					}

					is_theocracy = yes
				}
				trigger_else = {
					is_ruler = no
				}
			}
		}
	}
}

can_be_councilmember_king_trigger = {
	is_adult = yes
	independent = no
	prisoner = no
	is_incapable = no

	NOR = {
		trait = in_hiding
		has_character_modifier = resigned_in_anger

		reverse_has_opinion_modifier = {
			name = opinion_resigned_from_council
			who = liege
		}
	}

	trigger_if = {
		limit = { is_female = yes }

		liege = {
			OR = {
				has_religion_feature = religion_matriarchal
				has_religion_feature = religion_equal
				has_religion_feature = religion_feature_bon

				# Some religions don't mind so much who does what
				trigger_if = {
					limit = { is_feminist_trigger = yes }
					PREV = { is_feminist_trigger = yes }
				}

				# Laws permitting
				trigger_if = {
					limit = {
						OR = {
							has_law = status_of_women_1
							has_law = status_of_women_2
							has_law = status_of_women_3
						}
					}

					PREV = { is_landed = yes }
				}
				trigger_else = {
					has_law = status_of_women_4
				}

				# Other conditions under which females can be employed
				has_gender_equal_game_rule_trigger = yes
			}

			NOT = { has_religion_feature = religion_patriarchal }
		}
	}
	trigger_else = {
		liege = {
			NOT = { has_religion_feature = religion_matriarchal }
		}
	}
}

can_be_councilmember_emperor_trigger = {
	is_adult = yes
	independent = no
	prisoner = no
	is_incapable = no

	NOR = {
		trait = in_hiding
		has_character_modifier = resigned_in_anger

		reverse_has_opinion_modifier = {
			name = opinion_resigned_from_council
			who = liege
		}
	}

	trigger_if = {
		limit = { is_female = yes }

		liege = {
			OR = {
				has_religion_feature = religion_matriarchal
				has_religion_feature = religion_equal
				has_religion_feature = religion_feature_bon

				# Some religions don't mind so much who does what
				trigger_if = {
					limit = { is_feminist_trigger = yes }
					PREV = { is_feminist_trigger = yes }
				}

				# Laws permitting
				trigger_if = {
					limit = {
						OR = {
							has_law = status_of_women_1
							has_law = status_of_women_2
							has_law = status_of_women_3
						}
					}

					PREV = { is_landed = yes }
				}
				trigger_else = {
					has_law = status_of_women_4
				}

				# Other conditions under which females can be employed
				has_gender_equal_game_rule_trigger = yes
			}

			NOT = { has_religion_feature = religion_patriarchal }
		}
	}
	trigger_else = {
		liege = {
			NOT = { has_religion_feature = religion_matriarchal }
		}
	}
}

ere_elective_politician_titles_trigger = { # Used in Imperial Elective to determine AI behavior.
	OR = {
		has_job_title = job_marshal
		has_job_title = job_spymaster
		has_job_title = job_treasurer
		has_job_title = job_chancellor
		has_minor_title = title_despot
		has_minor_title = title_sebastokrator
		has_minor_title = title_caesar
		has_minor_title = title_kouropalates
		has_minor_title = title_anthypatos
	}
}

can_still_be_commander_byzantine_trigger = {
	primary_title = { temporary = no }

	liege = {
		character = FROMFROM
		has_law = succ_byzantine_elective
	}

	trigger_if = {
		limit = {
			NOT = { has_character_flag = special_marshal }
		}

		OR = {
			male_can_hold_minor_title_trigger = yes
			female_can_hold_minor_commander_title_trigger = yes
		}

		trigger_if = {
			limit = { religion = hindu }
			trait = kshatriya
		}

		is_adult = yes
	}

	is_inaccessible_or_incapable_trigger = no

	NOR = {
		has_character_modifier = guru
		has_character_modifier = refusing_to_lead
		war_with = FROMFROM

		any_liege = {
			war_with = FROMFROM
		}
	}

	OR = {
		higher_real_tier_than = BARON # Either potential commander is vassal...

		NOT = { # ...or there are no valid vassal candidates that can be commanders.
			custom_tooltip = {
				text = tooltip_byzantine_empire_can_appoint_commanders

				liege = {
					any_vassal = {
						higher_real_tier_than = BARON

						primary_title = { temporary = no }

						trigger_if = {
							limit = {
								NOT = { has_character_flag = special_marshal }
							}

							OR = {
								male_can_hold_minor_title_trigger = yes
								female_can_hold_minor_commander_title_trigger = yes
							}

							trigger_if = {
								limit = { religion = hindu }
								trait = kshatriya
							}

							is_adult = yes
						}

						is_inaccessible_or_incapable_trigger = no

						NOR = {
							has_character_modifier = guru
							has_character_modifier = refusing_to_lead
							has_job_title = job_chancellor
							has_job_title = job_marshal
							has_job_title = job_treasurer
							has_job_title = job_spymaster
							has_job_title = job_spiritual
							has_minor_title = title_commander
						}
					}
				}
			}
		}
	}
}

can_still_be_marshal_byzantine_trigger = {
	liege = {
		character = FROMFROM
		has_law = succ_byzantine_elective
	}

	NOR = {
		war_with = FROMFROM

		any_liege = {
			war_with = FROMFROM
		}
	}

	trigger_if = {
		limit = {
			NOT = { has_character_flag = special_chancellor }
		}

		trigger_if = {
			limit = { is_female = yes }

			liege = {
				OR = {
					has_religion_feature = religion_matriarchal
					has_religion_feature = religion_equal
					has_religion_feature = religion_feature_bon

					# Some religions don't mind so much who does what
					trigger_if = {
						limit = {
							OR = {
								religion = cathar
								religion = messalian
							}
						}

						religion = PREV
					}

					# Laws permitting
					trigger_if = {
						limit = { has_law = status_of_women_3 }

						PREV = {
							OR = {
								dynasty = PREV
								is_close_relative = PREV
								is_married = PREV
								is_consort = PREV
								is_landed = yes
								trait = nun
							}
						}
					}
					trigger_else = {
						has_law = status_of_women_4
					}

					# Other conditions under which females can be employed
					has_gender_equal_game_rule_trigger = yes
				}
			}
		}
		trigger_else = {
			liege = {
				NOT = { has_religion_feature = religion_matriarchal }
			}
		}

		trigger_if = {
			limit = { religion = hindu }
			NOT = { trait = kshatriya }
		}

		is_adult = yes
	}

	independent = no
	prisoner = no
	is_incapable = no

	NOR = {
		trait = in_hiding
		has_character_modifier = guru
		has_character_modifier = resigned_in_anger

		reverse_has_opinion_modifier = {
			name = opinion_resigned_from_council
			who = liege
		}
	}
}

byzantines_can_grant_commander_trigger = {
	trigger_if = {
		limit = { has_law = succ_byzantine_elective }  # Either not Imperial...

		custom_tooltip = {
			text = tooltip_byzantine_empire_can_appoint_commanders

			NOT = { #...Or there are no valid vassal candidates that can be commanders
				any_vassal = {
					higher_real_tier_than = BARON
					primary_title = { temporary = no }

					trigger_if = {
						limit = {
							NOT = { has_character_flag = special_marshal }
						}

						OR = {
							male_can_hold_minor_title_trigger = yes
							female_can_hold_minor_commander_title_trigger = yes
						}

						trigger_if = {
							limit = { religion = hindu }
							trait = kshatriya
						}

						is_adult = yes
					}

					is_inaccessible_or_incapable_trigger = no

					NOR = {
						has_job_title = job_chancellor
						has_job_title = job_marshal
						has_job_title = job_treasurer
						has_job_title = job_spymaster
						has_job_title = job_spiritual
						has_minor_title = title_commander
						has_character_modifier = guru
						has_character_modifier = refusing_to_lead
					}
				}
			}
		}
	}
}