source 'git@github.com:mileiq/MDLCocoapodSpecs.git'
source 'https://cdn.cocoapods.org/'

ensure_bundler! '~> 2.4.3'

project 'iOSRelease/goiq.xcodeproj', 'DebugStaging'=>:debug, 'DebugProduction'=>:debug

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

use_frameworks!

def shared_pods
    pod 'BitdriftCapture', '0.17.13'
    pod 'CaptureCocoaLumberjack', '0.17.13'
    pod 'CocoaLumberjack/Swift', '3.8.5'
    pod 'Firebase/Crashlytics', '10.29.0'
    pod 'Firebase/Analytics', '10.29.0'
    pod 'Mixpanel', '5.0.7'
    pod 'ZendeskAnswerBotSDK', '5.0.3'
    pod 'ZendeskChatSDK', '5.0.3'
    pod 'ZendeskSupportSDK', '8.0.3'
    pod 'UICKeyChainStore', '2.2.1'
    pod 'IQAuthentication', '1.9.11'
end
def app_test_shared_pods
    pod 'OCMock', '3.7.1'
end
target 'goiq' do
    shared_pods
    app_test_shared_pods
    
    pod 'IQShaker', :git => 'git@github.com:mileiq/IQShaker-iOS.git'
    pod 'Wormholy', :configurations => ['debugproduction','debugstaging','releasestaging']
    pod 'DIQDriveDetect', '5.0.1'
    pod 'FLEX', '5.22.10', :configurations => ['debugproduction','debugstaging','releasestaging']

    #pod 'Calabash', '~> 0.21.5', :configurations => ['ReleaseStaging']
    # Check the project for any spyntax/style guide issues
    # Included as a pod so we can:
    #   1. Use a consistent version accross all dev machines
    #   2. Enable swiftlint in VSTS easily
    #   3. Reduce the work for devs onboarding to the codebase since it's pre-installed
    pod 'SwiftLint', '0.53.0'
    pod 'AvoInspector', '1.3.0'
    pod 'GoogleMaps', '7.4.0'
    pod 'GooglePlaces', '7.4.0'

end
target 'mileiqTests' do
    app_test_shared_pods
end

target 'widgetDayView' do
    shared_pods
end

target 'widgetMonthStats' do
    shared_pods
end

target 'mileiqUITests' do
    shared_pods
    app_test_shared_pods
end

post_install do |installer_representation|
    installer_representation.pods_project.targets.each do |target|
        if ['IQAuthentication','IQShaker', 'CocoaLumberjack'].include? target.name
          target.build_configurations.each do |config|
            config.build_settings['SWIFT_VERSION'] = '5.0'
          end
        end
      end

    # Fixed XCode 14 signing pods issue
    installer_representation.generated_projects.each do |project|
      project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings["DEVELOPMENT_TEAM"] = "8Q3M7826DK"
        end
      end
    end

    #There was a code signing issue after use_frameworks, where each framework Provisioning Profile specifier was set to NO_SIGNING. This was breaking the build.
    # The fix was to add the logic in pod file to go through each and explicitly set the PROVISIONING_PROFILE_SPECIFIER to ''
    # Please refer: https://discuss.circleci.com/t/xcode-9-build-failures-due-to-code-signing-errors-in-pods/16713/2
    installer_representation.pods_project.build_configurations.each do |config|
        config.build_settings['PROVISIONING_PROFILE_SPECIFIER'] = ''
    end
    installer_representation.pods_project.targets.each do |target|
        if target.name.start_with? "Pods-widgetDayView" or target.name.start_with? "Pods-widgetMonthStats"
            target.build_configurations.each do |config|
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'AF_APP_EXTENSIONS=1']
                config.build_settings['OTHER_SWIFT_FLAGS'] = "COCOAPODS -D"
            end
        end
        target.build_configurations.each do |config|
            config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'

        end
        if target.name == 'IQAuthentication'
            puts "Building IQAuthentication"
            #for IQAuthentication we set the STAGING/PRODUCTION flag so the IQServer url etc are set
            target.build_configurations.each do |config|
                if config.name.downcase.include? "staging"
                    #puts "Building staging target #{target.name} config #{config.name}"
                    config.build_settings['OTHER_SWIFT_FLAGS'] ||= ['$(inherited)',  '-DSTAGING']
                    else
                    # puts "Building production target #{target.name} config #{config.name}"
                    config.build_settings['OTHER_SWIFT_FLAGS'] ||= ['$(inherited)', '-DPRODUCTION']
                end
            end
        end
        # In the new Xcode build system that came with Xcode 10, Xcode became smarter at detecting misconfigurations
        # It seems that multiple build commands produced the info.plist file in the rari framework, so to solve this i
        # am removing the build command the compiles the info plist source which solves the duplication issue
        if target.name == "rari"
            source_files = target.source_build_phase.files
            dummy = source_files.find do |file|
                #puts "File: #{file.file_ref.name}"
                file.file_ref.name == "Info.plist"
            end
            source_files.delete dummy
            puts "Deleted source file #{dummy.inspect} from target #{target.inspect}."
        end
    end
end
