###################################
#
# CHARLEMAGNE
# - Councillor decisions
#
###################################

# Written by Henrik "Groogy" Hansson

decisions = {
	help_liege_manage_titles = {
		is_high_prio = yes

		ai = no

		potential = {
			always = no # Disabled in CK2Plus

			OR = {
				has_job_title = job_chancellor
				has_job_title = job_treasurer
				has_job_title = job_spiritual
			}

			NOR = {
				had_character_flag = {
					flag = proposed_to_help_liege_with_titles
					years >= 2
				}

				trait = slothful
			}

			liege = {
				is_nomadic = no
				over_max_demesne_size >= 4
			}
		}

		allow = {
			liege = {
				show_scope_change = no

				over_max_demesne_size >= 4 # Show player why this is available

				trigger_if = {
					limit = { has_character_flag = has_been_proposed_about_titles }

					custom_tooltip = {
						text = tt_not_proposed_title_help_recently

						had_character_flag = {
							flag = has_been_proposed_about_titles
							days >= 14
						}
					}
				}

				trigger_if = {
					limit = { has_character_flag = refused_any_help_with_titles }

					custom_tooltip = {
						text = tt_not_refused_any_help_with_titles

						had_character_flag = {
							flag = refused_any_help_with_titles
							days >= 712
						}
					}
				}

				trigger_if = {
					limit = { has_character_flag = getting_help_with_titles }

					custom_tooltip = {
						text = tt_not_getting_help_with_titles

						had_character_flag = {
							flag = getting_help_with_titles
							days >= 800
						}
					}
				}
			}
		}

		effect = {
			set_character_flag = proposed_to_help_liege_with_titles

			liege = {
				set_character_flag = has_been_proposed_about_titles
				character_event = { id = CK2.18000 }
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	ask_help_to_manage_titles = {
		ai_check_interval = 12

	 	is_high_prio = yes

		ai = no

		potential = {
			always = no # Disabled in CK2Plus
			is_nomadic = no
			over_max_demesne_size >= 4

			trigger_if = {
				limit = { ai = yes }
				job_chancellor = { ai = no }
			}

			trigger_if = {
				limit = { has_character_flag = has_been_proposed_about_titles }

				had_character_flag = {
					flag = has_been_proposed_about_titles
					days >= 14
				}
			}

			trigger_if = {
				limit = { has_character_flag = refused_any_help_with_titles }

				had_character_flag = {
					flag = refused_any_help_with_titles
					days >= 712
				}
			}
		}

		allow = {
			over_max_demesne_size >= 4 # Show player why this is available

			trigger_if = {
				limit = {
					NOT = { job_chancellor = { always = yes } }
				}

				custom_tooltip = {
					text = tt_has_chancellor
					job_chancellor = { always = yes }
				}
			}

			trigger_if = {
				limit = { has_character_flag = getting_help_with_titles }

				custom_tooltip = {
					text = tt_recently_asked_help_with_titles

					had_character_flag = {
						flag = getting_help_with_titles
						days >= 800
					}
				}
			}
		}

		effect = {
			set_character_flag = getting_help_with_titles

			job_chancellor = {
				character_event = { id = CK2.18003 } # Start handing out titles
				character_event = { id = CK2.18001 } # Notify councillor
			}
		}

		ai_will_do = {
			factor = 1
		}
	}
}