﻿trade_agreement = {
	requires_approval = yes
	can_use_obligations = yes

	unlocking_technologies = {
		trade_pact
	}
	
	potential = {
		NOR = { 
			is_country_type = decentralized
			has_law = law_type:law_isolationism
		}
		scope:target_country = {
			NOR = { 
				is_country_type = decentralized 
				has_law = law_type:law_isolationism
			}
		}
		aggressive_diplomatic_plays_permitted = yes
		scope:target_country = {
			aggressive_diplomatic_plays_permitted = yes
		}
		has_diplomatic_relevance = scope:target_country
		NOT = { scope:target_country = { is_subject_of = root } }
		NOT = { is_subject_of = scope:target_country }				
	}
	
	possible = {
		NOT = { has_war_with = scope:target_country }
		NOT = {
			has_diplomatic_pact = {
				who = scope:target_country
				type = customs_union
			}					
		}
		is_junior_in_customs_union = no
		scope:target_country = { is_junior_in_customs_union = no }
		custom_tooltip = {
			text = DIPLO_ACTION_RELATIONS_POOR_OR_LESS_NOT
			scope:target_country.relations:root > relations_threshold:poor
		}			
		is_revolutionary = no
		scope:target_country = {
			is_revolutionary = no
		}
	}
	
	pact = {
		cost = 50
	
		is_trade_agreement = yes
		
		relations_progress_per_day = 1 # At 100, +1 relations
		relations_improvement_max = 80	
	
		is_about_to_auto_break = {
            scope:target_country.relations:root < 0 # this is: cold + 10
        }

		should_auto_break = {
			custom_tooltip = {
			
				text = DIPLO_ACTION_RELATIONS_POOR_OR_LESS

                # make sure to update is_about_to_auto_break when changing this:
				scope:target_country.relations:root <= relations_threshold:poor
			}		
		}

		should_invalidate = {
			OR = {
				has_war_with = scope:target_country				
				is_country_type = decentralized
				scope:target_country = { is_country_type = decentralized }
				aggressive_diplomatic_plays_permitted = no
				scope:target_country = { aggressive_diplomatic_plays_permitted = no }
				is_subject_of = scope:target_country
				scope:target_country = { is_subject_of = root }
				is_junior_in_customs_union = yes
				scope:target_country = { is_junior_in_customs_union = yes }	
				scope:target_country = { has_law = law_type:law_isolationism }	
				has_law = law_type:law_isolationism
				NOT = { has_diplomatic_relevance = scope:target_country }
			}
		}

		break_effect = {
			change_relations = { country = scope:target_country value = -10 }
		}
	}

	ai = {
		check_acceptance_for_will_break = yes
		check_acceptance_for_will_propose = yes
	
		accept_score = {
			value = 0
			
			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_BASE"
				value = -100
			}			
			
			if = {
				limit = { 
					"scope:actor.num_mutual_trade_route_levels_with_country(root)" < 1
				}
				
				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_NO_MUTUAL_TRADE_ROUTES"
					value = -1000
				}				
			}
			else = {
				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_MUTUAL_TRADE_ROUTES"
					value = "scope:actor.num_mutual_trade_route_levels_with_country(root)"
					multiply = 2
					max = 75
				}				
			}

			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_GDP"
				value = "scope:actor.ai_gdp_comparison(root)"
				multiply = 2
				min = -10
				max = 10
			}	

			if = {
				limit = {
					"scope:actor.ai_ideological_opinion(root)" > 0
				}
				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_IDEOLOGICAL_OPINION"
					value = "scope:actor.ai_ideological_opinion(root)"
					multiply = 0.25
					max = 10
				}					
			}
			else_if = {
				limit = {
					"scope:actor.ai_ideological_opinion(root)" < 0
				}
				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_IDEOLOGICAL_OPINION_NEGATIVE"
					value = "scope:actor.ai_ideological_opinion(root)"
					multiply = 0.25
					min = -10
				}					
			}							
			
			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_ATTITUDE"
				if = {
					limit = {
						OR = {
							has_attitude = {
								who = scope:actor
								attitude = genial
							}
							has_attitude = {
								who = scope:actor
								attitude = conciliatory
							}							
							has_attitude = {
								who = scope:actor
								attitude = loyal
							}
							has_attitude = {
								who = scope:actor
								attitude = protective
							}							
						}
					}
					value = 50
				}
				if = {
					limit = {
						has_attitude = {
							who = scope:actor
							attitude = cooperative
						}
					}
					value = 25
				}				
				if = {
					limit = {
						has_attitude = {
							who = scope:actor
							attitude = cautious
						}
					}
					value = -50
				}					
				if = {
					limit = {
						OR = {
							has_attitude = {
								who = scope:actor
								attitude = antagonistic
							}
							has_attitude = {
								who = scope:actor
								attitude = domineering
							}	
							has_attitude = {
								who = scope:actor
								attitude = belligerent
							}	
							has_attitude = {
								who = scope:actor
								attitude = rebellious
							}							
						}
					}
					value = -1000
				}							
			}			

			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_RELATIONS"								
				if = {
					limit = {
						"relations(scope:actor)" < relations_threshold:friendly
					}
					value = 0
				}
				if = {
					limit = {
						"relations(scope:actor)" >= relations_threshold:amicable
						"relations(scope:actor)" < relations_threshold:friendly
					}
					value = 35
				}	
				if = {
					limit = {
						"relations(scope:actor)" >= relations_threshold:friendly
					}
					value = 50
				}				
			}
			
			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_INFAMY"
				if = {
					limit = {
						"scope:actor.infamy" >= infamy_threshold:infamous
						"scope:actor.infamy" < infamy_threshold:notorious
					}
					value = -10
				}	
				if = {
					limit = {
						"scope:actor.infamy" >= infamy_threshold:notorious
						"scope:actor.infamy" < infamy_threshold:pariah
					}
					value = -25
				}
				if = {
					limit = {
						"scope:actor.infamy" >= infamy_threshold:pariah
					}
					value = -50
				}					
			}								
		}	

		propose_score = {
			value = 10
		}

		propose_break_score = {
			value = 10
		}
		
		use_obligation_chance = {
			value = 0
	
			add = {
				if = {
					limit = {
						scope:target_country = { country_rank = root.country_rank }
					}					
					value = 25
				}			
			}
	
			add = {
				if = {
					limit = {
						scope:target_country = { country_rank > root.country_rank }
					}					
					value = 50
				}			
			}
		}
		
		owe_obligation_chance = {
			value = 0			
		}	
	}
}