country_decisions = {

	spanish_nation = {
		major = yes
		potential = {
			normal_or_historical_nations = yes
			OR = {
				ai = no
				is_playing_custom_nation = no
			}
			NOT = { tag = SPA }
			NOT = { tag = PAP }
			NOT = { tag = HLR }
			NOT = { tag = FRA }		# Basque is a valid culture for both FRA and SPA
			NOT = { tag = KNI }		# Maltese is part of iberian culture group
			NOT = { tag = ADU }
			NOT = { religion_group = muslim }
			OR = {
				ai = no
				ARA = { ai = no }
				AND = {
					NOT = { tag = ARA }
					NOT = { tag = CAS }
				}
				is_year = 1500
			}
			OR = {
				ai = no
				AND = {
					ai = yes
					num_of_cities = 3
					NOT = { exists = SPA }
				}
			}
			OR = {
				ai = no
				AND = {
					ai = yes
					NOT = { tag = POR }
				}
			}
			OR = {
				culture_group = iberian
				primary_culture = basque
			}
			is_colonial_nation = no
			OR = {
				is_former_colonial_nation = no
				AND = {
					is_former_colonial_nation = yes
					ai = no
				}
			}
		}
		allow = {
			NOT = { exists = SPA }
			adm_tech = 15
			is_subject = no
			is_nomad = no
			is_at_war = no
			owns_core_province = 213	# Barcelona
			owns_core_province = 214	# Aragón
			owns_core_province = 215	# Castilla La Vieja
			owns_core_province = 216	# Salamanca
			owns_core_province = 224	# Andalucia
			owns_core_province = 219	# Toledo
			owns_core_province = 220	# Valencia
			owns_core_province = 223	# Granada
			iberia_region = {
				type = all
				NOT = { owner = { religion_group = muslim } }
			}
		}
		effect = {
			change_tag = SPA
			if = {
				limit = {
					is_part_of_hre = yes
					is_elector = no
					is_emperor = no
				}
				every_owned_province = {
					limit = {
						is_part_of_hre = yes
					}
					set_in_empire = no
				}
			}
			if = {
				limit = { NOT = { government_rank = 2 } }
				set_government_rank = 2
			}
			if = {
				limit = {
					has_custom_ideas = no
					OR = {
						ai = no
						AND = {
							ai = yes
							has_idea_group = default_ideas
						}
					}
				}
				country_event = { id = ideagroups.1 } #Swap Ideas
			}
			custom_tooltip = spanish_unification_effect.tooltip
			hidden_effect = {
				iberia_region = {
					limit = {
						NOT = { area = macaronesia_area }
						NOT = { area = alentejo_area }
						NOT = { area = beieras_area }
					}
					add_permanent_claim = SPA
				}
			}
			add_country_modifier = {
				name = "centralization_modifier"
				duration = 7300
			}
			add_prestige = 25
		}
		ai_will_do = {
			factor = 1
		}
		ai_importance = 400
	}
	
	spanish_nation_diplomatically = {
		major = yes
		potential = {
			normal_or_historical_nations = yes
			OR = {
				ai = no
				is_playing_custom_nation = no
			}
			is_tutorial_active = no
			tag = CAS
			owns = 219
			OR = {
				ai = no
				AND = {
					ai = yes
					OR = {
						ARA = {	junior_union_with = CAS	}
						ARA = {	vassal_of = CAS	}
					}
				}
			}
			NOT = { #This overlaps with allow for AI, is meant to negate do_not_integrate
				ai = yes
				ARA = { num_of_cities = 32 } #Keep this number the same as below
			}
		}
		allow = {
			adm_tech = 15
			is_subject = no
			is_nomad = no
			is_at_war = no
			legitimacy = 100
			OR = {
				tag = GRA
				NOT = {
					iberia_region = {
						owned_by = GRA
					}
				}
			}
			OR = {
				ARA = {	junior_union_with = CAS	}
				ARA = {	vassal_of = CAS	}
			}
			ARA = {
				NOT = { num_of_cities = 32 } #Keep this number the same as above. Original 17 +15
			}
		}
		effect = {
			change_tag = SPA
			if = {
				limit = {
					is_part_of_hre = yes
					is_elector = no
				}
				every_owned_province = {
					limit = {
						is_part_of_hre = yes
					}
					set_in_empire = no
				}
			}
			if = {
				limit = { NOT = { government_rank = 2 } }
				set_government_rank = 2
			}
			if = {
				limit = {
					ARA = {
						ai = yes
					}
				}
				inherit = ARA
			}	
			custom_tooltip = spanish_unification_effect.tooltip
			hidden_effect = {
				iberia_region = {
					limit = {
						NOT = { area = macaronesia_area }
						NOT = { area = alentejo_area }
						NOT = { area = beieras_area }
					}
					add_permanent_claim = SPA
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
		ai_importance = 200
		do_not_integrate = ARA
	}	
	
}
