# Uncomment this line to define a global platform for your project
platform :ios, '13.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))

  # AdMob Mediation: 필요한 네트워크만 주석 해제하여 사용 (AdMob 12.x 호환)
  pod 'GoogleMobileAdsMediationUnity', '~> 4.16.3.0'
  pod 'GoogleMobileAdsMediationMoloco', '~> 4.1.0.0'
  pod 'GoogleMobileAdsMediationAppLovin', '~> 13.5.0.0'
  pod 'GoogleMobileAdsMediationInMobi', '~> 11.0.0.0'
  pod 'GoogleMobileAdsMediationVungle', '~> 7.6.1.0'
  pod 'GoogleMobileAdsMediationFyber', '~> 8.4.1.0'
  pod 'GoogleMobileAdsMediationMintegral', '~> 7.7.9.1'
  pod 'GoogleMobileAdsMediationPangle', '~> 7.7.0.6.0'
  pod 'GoogleMobileAdsMediationIronSource', '~> 9.0.0.0.0'

  target 'RunnerTests' do
    inherit! :search_paths
  end
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end

  # Mediation 어댑터(InMobi 등) 사용 시 필요: Runner 앱 타겟 Other Linker Flags에 -ObjC 추가
  runner_project_path = File.join(File.dirname(__FILE__), 'Runner.xcodeproj')
  if File.exist?(runner_project_path)
    require 'xcodeproj'
    project = Xcodeproj::Project.open(runner_project_path)
    project.native_targets.each do |target|
      if target.name == 'Runner'
        target.build_configurations.each do |config|
          flags = config.build_settings['OTHER_LDFLAGS'] || ['$(inherited)']
          flags = [flags] if flags.is_a?(String)
          config.build_settings['OTHER_LDFLAGS'] = (flags + ['-ObjC']).uniq
        end
        break
      end
    end
    project.save
  end
end
