#! /usr/bin/env ruby

require "spaceship"
# Until they fix deliver to remove old, need to do this
# https://github.com/fastlane/fastlane/issues/1529#issuecomment-193381124
#Spaceship.login( "appdev@sharefaith.com", "c~3+#v[fB}:X" )
Spaceship::Tunes.login( "appdev@sharefaith.com", "c~3+#v[fB}:X" )
du = Spaceship::Tunes.client.du_client

bundle_id = ARGV[0]
#target_version = ARGV[1]
#puts( "Clearing for " + bundle_id + " version " + target_version )

app = Spaceship::Tunes::Application.find bundle_id

#Should be done by Java now
# if app.edit_version #:
#     v = app.edit_version
#     v.version = target_version
#     v.save!
#     puts( "Set version number" )
# else#:
# 	puts( "Creating editable version..." )
#     app.create_version!(target_version)
# end
# 
# appv = app.edit_version
# 
# puts( "Clearing..." )
# appv.screenshots.each do |language, screenshots| #:
#   screenshots.each do |sc| #:
#     appv.upload_screenshot!(nil, sc.sort_order, sc.language, sc.device_type)
#   end
# end
appv = app.edit_version

appv.languages[0].fetch("displayFamilies").fetch("value").each { |x|
    if x["name"] != "ipadPro" && x["name"] != "iphone6Plus" then
        x["scaled"]["value"] = true
    end
}

puts( "Saving..." )
appv.save!