﻿REPLACE:restore_union = {
	icon = "gfx/interface/icons/war_goals/enforce_treaty_article.dds"

	kind = custom

	settings = {
		require_target_be_part_of_war
		turns_into_subject
		requires_interest

		# Validation
		conflicts_with_make_subject
		validate_conflicts_make_subject
	}

	execution_priority = 12

	contestion_type = control_half_target_country_states

	target_type = country

	possible = {
		# trigger to determine if a goal with its target data is listed when selecting a war goal in the diplo play panel
		# scopes: root = holder, creator_country, diplomatic_play, target_country, target_state, stakeholder, target_region, article_options
		ROOT = {
			has_law = law_type:law_monarchy
			has_variable = por_seeking_restore_union_var
		}
		scope:target_country ?= {
			c:BRZ ?= this
		}
		has_strategic_region_interest_tier = {
			strategic_region = scope:target_region
			value >= 2
		}
	}

	valid = {
		# trigger in addition to some basic validation code-side
		# scopes: root = holder, creator_country, diplomatic_play, target_country, target_state, stakeholder, target_region, article_options
		ROOT = {
			has_law = law_type:law_monarchy
			has_variable = por_seeking_restore_union_var
		}
		scope:target_country ?= {
			c:BRZ ?= this
		}
	}

	maneuvers = {
		value = 0

		add = {
			desc = "MANEUVERS_BASE_VALUE"
			value = 10
		}

		scope:target_country = {
			multiply = {
				desc = "MANEUVERS_TARGET_COUNTRY_POPULATION_FACTOR"
				value = total_population
				divide = define:NDiplomacy|SWAY_OFFER_WARGOAL_MANEUVERS_COST_POPULATION_SCALING_FACTOR
				multiply = define:NDiplomacy|SWAY_OFFER_WARGOAL_MANEUVERS_COST_POPULATION_SCALING_MULTIPLIER
				max = define:NDiplomacy|SWAY_OFFER_WARGOAL_MANEUVERS_COST_POPULATION_SCALING_MULTIPLIER_MAX_TOTAL
			}
		}
	}

	infamy = {
		value = 0

		add = {
			desc = "INFAMY_BASE_VALUE"
			value = 0.5
		}

		scope:target_country = {
			multiply = {
				desc = "INFAMY_TARGET_COUNTRY_POPULATION_FACTOR"
				add = {
					every_scope_state = {
						add = {
							value = state_population
							divide = define:NDiplomacy|WAR_GOAL_INFAMY_POPULATION_SCALING_FACTOR
							multiply = define:NDiplomacy|WAR_GOAL_INFAMY_POPULATION_SCALING_MULTIPLIER
							multiply = {
								if = {
									limit = {
										is_incorporated = no
									}
									value = 1
									add = define:NDiplomacy|WAR_GOAL_INFAMY_UNINCORPORATED_FACTOR
								}
							}
							max = define:NDiplomacy|WAR_GOAL_INFAMY_POPULATION_SCALING_MULTIPLIER_MAX_PER_STATE
						}
					}
				}
				add = 1
				max = define:NDiplomacy|WAR_GOAL_INFAMY_POPULATION_SCALING_MULTIPLIER_MAX_TOTAL
			}
		}

		multiply = {
			desc = "concept_interest_tier"
			value = 1

			# Tier 0-1 (none, observant): high infamy increase
			if = {
				limit = {
					NOT = {
						has_strategic_region_interest_tier = {
							strategic_region = scope:target_region
							value >= 2
						}
					}
				}
				add = interest_tier_effect_infamy_cost_increase_high_value
			}

			# Tier 2 (engaged): medium infamy increase
			if = {
				limit = {
					has_strategic_region_interest_tier = {
						strategic_region = scope:target_region
						value >= 2
					}
					NOT = {
						has_strategic_region_interest_tier = {
							strategic_region = scope:target_region
							value >= 3
						}
					}
				}
				add = interest_tier_effect_infamy_cost_increase_medium_value
			}

			# Tier 5 (hegemonic): medium infamy decrease
			if = {
				limit = {
					has_strategic_region_interest_tier = {
						strategic_region = scope:target_region
						value >= 5
					}
				}
				add = interest_tier_effect_infamy_cost_decrease_medium_value
			}
		}

		min = {
			desc = "INFAMY_MINIMUM_VALUE"
			value = 2
		}
	}

	on_enforced = {
		# script effect on top of the predefined code effect
		scope:target_country ?= {
			activate_law = law_type:law_monarchy
		}
		ROOT = {
			create_diplomatic_pact = {
				country = scope:target_country
				type = personal_union
			}
		}
	}

	ai = {
		is_significant_demand = yes
	}
}
