########################################################
# AIR PRODUCTION – DOCTRINE-DOMINANT (IMPROVED)
########################################################

air_production_default = {
    enable = { 
        always = yes 
    }
    abort_when_not_enabled = yes

    # Softer baselines so doctrines blow things up
    ai_strategy = { type = unit_ratio id = fighter value = 30 }
    ai_strategy = { type = unit_ratio id = cas value = 15 }
    ai_strategy = { type = unit_ratio id = tactical_bomber value = 10 }
    ai_strategy = { type = unit_ratio id = strategic_bomber value = 0 }
    ai_strategy = { type = unit_ratio id = maritime_patrol_plane value = 2 }
}

light_aircraft_production = {
    enable = { is_eligible_for_light_aircraft_production = yes }
    abort_when_not_enabled = yes

    ai_strategy = { type = unit_ratio id = fighter value = 60 }
    ai_strategy = { type = unit_ratio id = cas value = 20 }
    ai_strategy = { type = air_factory_balance value = 40 }
}

tac_bomber_production_default = {
    enable = { is_eligible_for_medium_aircraft_production = yes }
    abort_when_not_enabled = yes

    ai_strategy = { type = unit_ratio id = tactical_bomber value = 20 }
    ai_strategy = { type = unit_ratio id = cas value = -5 }
}

# Operational Integrity -> TAC-dominant with STRAT support
tac_bomber_production_operational_integrity = {
    enable = { 
        is_eligible_for_medium_aircraft_production = yes
        has_doctrine = new_operational_integrity
    }
    abort_when_not_enabled = yes

    # TAC-dominant but more integrated
    ai_strategy = { type = unit_ratio id = tactical_bomber value = 40 }
    ai_strategy = { type = unit_ratio id = fighter value = 15 }  # Fighter is law
    ai_strategy = { type = unit_ratio id = strategic_bomber value = 10 }  # Some strategic capability
    ai_strategy = { type = unit_ratio id = cas value = -10 }
}

strat_bomber_air_production_default = {
    enable = { is_eligible_for_heavy_aircraft_production = yes }
    abort_when_not_enabled = yes

    ai_strategy = { type = unit_ratio id = strategic_bomber value = 10 }
    ai_strategy = { type = unit_ratio id = fighter value = -5 }
    ai_strategy = { type = unit_ratio id = heavy_fighter value = 75 }
}

# Strategic Destruction -> STRAT-dominant with CAS support
strat_bomber_air_production_strategic_destruction = {
    enable = { 
        is_eligible_for_heavy_aircraft_production = yes
        has_doctrine = new_strategic_destruction
    }
    abort_when_not_enabled = yes

    # STRAT-dominant but more integrated
    ai_strategy = { type = unit_ratio id = strategic_bomber value = 45 }
    ai_strategy = { type = unit_ratio id = fighter value = 20 }  # Fighter is law - MORE fighters for escort
    ai_strategy = { type = unit_ratio id = heavy_fighter value = 70 }
    ai_strategy = { type = unit_ratio id = cas value = 20 }  # Some ground attack capability
    ai_strategy = { type = unit_ratio id = tactical_bomber value = -10 }
}

# Battlefield Support -> CAS-dominant with TAC support
cas_doctrine = {
    enable = { has_doctrine = new_battlefield_support }
    abort_when_not_enabled = yes

    # CAS-dominant but more integrated
    ai_strategy = { type = unit_ratio id = cas value = 45 }
    ai_strategy = { type = unit_ratio id = fighter value = 25 }  # Fighter is law - MORE fighters
    ai_strategy = { type = unit_ratio id = tactical_bomber value = 20 }  # Some medium bomber capability
    ai_strategy = { type = unit_ratio id = strategic_bomber value = -15 }
}

cv_aircraft_production = {
    enable = { is_eligible_for_cv_aircraft_production = yes }
    abort_when_not_enabled = yes

    # Keep carriers usable but not factory hogs
    ai_strategy = { type = equipment_production_min_factories id = cv_fighter value = 1 }
    ai_strategy = { type = equipment_production_min_factories id = cv_naval_bomber value = 1 }
    ai_strategy = { type = equipment_production_min_factories id = cv_cas value = 1 }
}

other_aircraft_production = {
    enable = { is_eligible_for_medium_aircraft_production = yes }
    abort_when_not_enabled = yes

    # ai_strategy = { type = equipment_production_min_factories id = air_transport value = 1 }
}

# Reduced maritime patrol emphasis - only for serious naval threats
maritime_patrol_production = {
    enable = { enemies_naval_strength_ratio > 2.5 }  # Higher threshold
    abort_when_not_enabled = yes

    ai_strategy = { type = unit_ratio id = maritime_patrol_plane value = 5 }  # Reduced from 8
}

# Air war dynamic production priorities
light_aircraft_production_losing_air_war = {
	enable = {
		is_eligible_for_light_aircraft_production = yes
		has_war = yes
		any_enemy_country = {
			has_deployed_air_force_size = {
				size > ROOT.num_deployed_planes_with_type@small_plane_airframe
				type = fighter
			}
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = unit_ratio id = fighter value = 20 }  # Fighter is law
	ai_strategy = { type = unit_ratio id = cas value = -15 }
}

light_aircraft_production_winning_air_war = {
	enable = {
		is_eligible_for_light_aircraft_production = yes
		has_war = yes
		NOT = {
			any_enemy_country = {
				has_deployed_air_force_size = {
					size > ROOT.num_deployed_planes_with_type@small_plane_airframe
					type = fighter
				}
			}
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = unit_ratio id = fighter value = -15 }  # Still maintain fighters
	ai_strategy = { type = unit_ratio id = cas value = 20 }
}

# Air war dynamic production adjustments to cas-fighter ratios and other
aNCFO_AI_cas_air_prod_2 = {
	enable = {
		check_variable = { num_deployed_planes_with_type@cas < num_deployed_planes_with_type@fighter }
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = unit_ratio
		id = cas
		value = 35
	}

	ai_strategy = {
		type = equipment_production_factor
		id = cas
		value = 10
	}

	ai_strategy = {
		type = equipment_production_min_factories
		id = cas
		value = 1
	}
}

aNCFO_AI_bomb_air_prod_2 = {
	enable = {
		is_major = yes
		num_of_nukes > 0
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = unit_ratio
		id = strategic_bomber
		value = 100
	}

	ai_strategy = {
		type = equipment_production_factor
		id = strategic_bomber
		value = 100
	}

	ai_strategy = {
		type = equipment_variant_production_factor
		id = large_plane_airframe
		value = 35
	}

	ai_strategy = {
		type = equipment_variant_production_factor
		id = nuclear_missile_equipment
		value = 35
	}
}

# FIGHTER IS LAW - prioritize fighters when CAS is too high
aNCFO_AI_focus_on_fighters = {
	enable = {
		is_major = yes
		check_variable = { num_deployed_planes_with_type@cas > num_deployed_planes_with_type@fighter }
		check_variable = { var = num_deployed_planes_with_type@cas value = num_deployed_planes_with_type@fighter compare = greater_than_or_equals }
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = unit_ratio
		id = fighter
		value = 60  # Increased - fighter is law!
	}

	ai_strategy = {
		type = equipment_production_factor
		id = fighter
		value = 100
	}

	ai_strategy = {
		type = equipment_production_min_factories
		id = fighter
		value = 8
	}

	ai_strategy = {
		type = unit_ratio
		id = cas
		value = -350
	}

	ai_strategy = {
		type = equipment_production_factor
		id = cas
		value = -100
	}

	ai_strategy = {
		type = equipment_production_min_factories
		id = cas
		value = -1
	}
}

aNCFO_AI_fighter_equipment_production_min_factories = {
	enable = {
		num_of_military_factories > 35
		OR = {
			has_war_with_major = yes
			AND = {
				is_major = yes
				has_war = yes
			}
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = equipment_production_min_factories
		id = fighter
		value = 5  # Increased from 4 - fighter is law
	}
}

aNCFO_AI_cas_equipment_production_min_factories = {
	enable = {
		num_of_military_factories > 50
		OR = {
			has_war_with_major = yes
			AND = {
				is_major = yes
				has_war = yes
			}
		}
		check_variable = { num_deployed_planes_with_type@cas < num_deployed_planes_with_type@fighter }
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = equipment_production_min_factories
		id = cas
		value = 1
	}
}

default_transport_production = {
	enable = {
		is_major = yes
		OR = {
			has_tech = early_transport_plane
			has_tech = bba_early_transport_plane
		}
		check_variable = { num_deployed_planes_with_type@air_transport < 1000 }
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = unit_ratio
		id = air_transport
		value = -99
	}

	ai_strategy = {
		type = equipment_production_factor
		id = air_transport
		value = -99
	}

	ai_strategy = {
		type = equipment_production_min_factories
		id = air_transport
		value = 1
	}
}

default_spyplanes_production = {
	enable = {
		is_major = yes
		OR = {
			has_tech = scout_plane1
			has_tech = photo_reconnaisance
		}
		check_variable = { num_deployed_planes_with_type@scout_plane < 100 }
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = unit_ratio
		id = scout_plane
		value = -99
	}

	ai_strategy = {
		type = equipment_production_factor
		id = scout_plane
		value = -99
	}

	#ai_strategy = {
	#	type = equipment_production_min_factories
	#	id = scout_plane
	#	value = 1
	#}
}

minors_dont_spy = {
	enable = {
		OR = {
			has_tech = scout_plane1
			has_tech = photo_reconnaisance
		}
		is_major = no
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = unit_ratio
		id = scout_plane
		value = -100
	}
}