# frozen_string_literal: true
#---------------------------------------------------------------------------------------------------
# Unless we are in a deployment mode or are running from a script bundle, stop immediately
if File.basename($PROGRAM_NAME) == 'bundle' && (ARGV.empty? || ARGV.include?('install') || ARGV.include?('update')) && !ARGV.include?('--deployment') && !ENV['SCRIPT_BUNDLE']
  require_relative 'config/initializers/string_colors'
  puts
  puts 'ERROR: You seem to be running a bundle install command directly, this does not work anymore.'.red
  puts
  puts 'Please note: We are using a complex MRI/jruby setup now and that means we need'
  puts 'to maintain bundler cache for both platforms. To help you do that, we have'
  puts "created a #{'./script/bundle'.yellow} script. Please use that script to manage gems."
  puts
  puts 'If you are in a deployment/CI situation, please use the --deployment flag for bundle install'
  puts
  exit!(1)
end

jruby_version = File.read(File.join(__dir__, '.jruby-version')).strip.delete_prefix('jruby-')
supported_bundler_version = File.read(File.join(__dir__, '.bundler-version-supported')).strip

ALL_DEVELOPMENT_ENVS = %i[development crawler_development]
ALL_TEST_ENVS = %w[test legacy_test crawler_test]

#---------------------------------------------------------------------------------------------------
# Pull gem index from rubygems
source 'https://rubygems.org'

# Pin the version of bundle we support
gem 'bundler', supported_bundler_version

# Load Swiftype Gems -- use our private gem repo
source 'https://artifactory.elstc.co/artifactory/api/gems/swiftype-gems' do
  gem 'fortitude', '= 0.9.6.swiftype01'
end

#---------------------------------------------------------------------------------------------------
# Default dependencies for all environments (including the crawler)
#---------------------------------------------------------------------------------------------------
group :default, :crawler do
  gem 'addressable'
  gem 'bson', '~> 4.2.2'
  gem 'concurrent-ruby', '~> 1.1.4'
  gem 'elasticsearch', '~> 7.5.0'
  gem 'manticore', :platform => 'jruby'
  gem 'nokogiri', '~> 1.10.10', :require => false
  gem 'rake', '~> 12.3.2'
  gem 'rails', '= 4.2.11.3'

  # We need to bundle TZ data because on windows and in some minimal Linux installations there is
  # no system-level TZ data info and the app blows up when trying to use timezone information
  # See https://github.com/tzinfo/tzinfo/wiki/Resolving-TZInfo::DataSourceNotFound-Errors for details
  gem 'tzinfo-data'
end

#---------------------------------------------------------------------------------------------------
# Default dependencies for all Rails environments (but not for the crawler)
#---------------------------------------------------------------------------------------------------
# If you update this gem, please update the 03-rails-assets.rb initializer as well
gem 'sprockets-rails', '~> 2'
gem 'sprockets', '< 3'
gem 'webpacker'

gem 'test-unit' # They want it here since rails 3.2.22

# This is used to run our workers under Jetty
gem 'jruby-rack-worker', :require => false, :platform => 'jruby'

# EsqueuesMe - ActiveJob synchronous job processing framework based on Elasticsearch
gem 'esqueues-me', :path => 'vendor/esqueues-me'
gem 'es_reconnect', '~> 0.0.1', :path => 'vendor/es_reconnect'

# Swiftype utils is a multi-platform gem and we can't use it via a git dependency.
# Need to release it for both platforms first!
gem 'swiftype_utils', '~> 0.2.12'

gem 'jquery-rails', '~> 4.4.0'
gem 'jquery-ui-rails', '~> 6.0.1'

gem 'devise', '~> 4.7.1'
gem 'devise-token_authenticatable', '~> 1.1.0'
gem 'valid_email', '0.0.12', :require => 'valid_email/email_validator'

gem 'ipaddress'
gem 'hashie', '= 3.6.0'

gem 'marco-polo'
gem 'uea-stemmer'
gem 'stringex', :require => 'stringex_lite'

gem 'state_machines', '~> 0.4.0'
gem 'state_machines-activemodel', '~> 0.3.0'

gem 'httpclient'
gem 'faraday', '= 0.15.2'
gem 'faraday_middleware', '= 0.12.2'

gem 'statsd-instrument', '= 2.1.1'
gem 'kaminari', '>= 1.2.1'

gem 'rack', '>= 1.6.12'
gem 'rack-attack'

gem 'rack-ssl-enforcer'
gem 'cancancan'

gem 'jwt', '~> 1.5.1'

# Security updates
gem 'rack-cors', '~> 1.0.4', :require => 'rack/cors'
gem 'json', '~> 2.3.1'

gem 'breach-mitigation-rails'

# Used in multiple places around the codebase (see all the references to Zip::File)
gem 'rubyzip', '~> 1.3.0', :require => 'zip'

gem 'awesome_print', '~> 1.8.0'

gem 'htmlentities'
gem 'mime-types', '= 3.1'

gem 'gson', :platform => 'jruby'

gem 'childprocess', '3.0.0'

# Frito Pie
gem 'signet', '0.12'
gem 'octokit'
gem 'google-api-client', '0.41.0'
gem 'memoist', '0.16.0'
gem 'zendesk_api', '1.19.0'
gem 'restforce', '3.1.0'

# Connectors
gem 'salesforce_bulk_query', :git => 'git@github.com:gooddata/salesforce_bulk_query', :ref => '9695873'

# Used for config file validation
gem 'json-schema', :platform => :jruby

# We have an ability to inject Elastic APM agent into self-managed versions of the product
gem 'elastic-apm', '2.3.1', :require => false, :platform => :jruby # FIXME: Upgrade this

# ^ elastic-apm dependency, remove the pin when upgrading
gem 'http', '4.0.4', :platform => :jruby

# Make sure to keep these in sync (mongo driver depends on a specific version of doorkeeper)
gem 'doorkeeper', '4.4.3'
gem 'doorkeeper-mongodb', '~> 4.2', :platform => :mri

gem 'kramdown', '>= 2.3.0'

#---------------------------------------------------------------------------------------------------
# SaaS-only default dependencies
#---------------------------------------------------------------------------------------------------
platforms(:mri) do
  gem 'imgix', '= 1.1.0'

  # This doesn't work on jruby, so I've scoped it down to MRI platform and using plain ruby json there
  gem 'oj', '= 3.6.0'

  # MySQL access driver
  gem 'mysql2', '~> 0.4.0'

  # CPK support for AR
  gem 'composite_primary_keys', '= 8.1.2'

  # MongoDB Access gems
  gem 'mongo'
  gem 'mongoid', '= 5.2.0' # > 5.2.0 has scary Regexp namespace collision https://jira.mongodb.org/browse/MONGOID-4450
  gem 'kaminari-mongoid', '~> 1.0.1'

  gem 'state_machines-mongoid', :git => 'git@github.com:smartinm/state_machines-mongoid.git', :ref => '0b61e7afeb192366b713ea7acc7093f10e8d6352'
  gem 'state_machines-activerecord', '~> 0.3.0'

  gem 'flex_columns', '= 1.0.9'

  gem 'stripe', '< 4'

  gem 'kjess'

  gem 'rabl', '= 0.8.0'
end

#---------------------------------------------------------------------------------------------------
# Crawler-only default dependencies
#---------------------------------------------------------------------------------------------------
# This group acts as a default group for standalone crawler scripts/tests/etc
group :crawler do
  # TBD
end

#---------------------------------------------------------------------------------------------------
# Special-case dependencies
#---------------------------------------------------------------------------------------------------
# Dependencies used on CI for building Rails assets
group :assets do
  gem 'uglifier', '>= 1.0.3'
  gem 'sass-rails', '~> 5.0'
  gem 'autoprefixer-rails'
  gem 'js-routes'
end

# Dependencies used on CI to build war files for self-managed production deployments
group :togo_not_bundled do
  gem 'jruby-jars', jruby_version, :require => false, :platform => 'jruby'
  gem 'warbler', :require => false, :platform => 'jruby'
end

#---------------------------------------------------------------------------------------------------
# Development dependencies for Rails environments (but not for the crawler)
#---------------------------------------------------------------------------------------------------
group :development do
  gem 'puma', '~> 4.3.5' # used for development environments only
  gem 'mail_view', '~> 2.0'
  gem 'better_errors'

  gem 'execjs'

  # Add ffaker to create fake people in demo accounts
  gem 'ffaker'
end

#---------------------------------------------------------------------------------------------------
# Development and test dependencies for all environments (including the crawler)
#---------------------------------------------------------------------------------------------------
group(*ALL_DEVELOPMENT_ENVS) do
  gem 'rubocop', '0.52.1'

  gem 'ruby-debug-ide'
  gem 'pry-remote', :platform => 'jruby'
  gem 'pry-nav', :platform => 'jruby'
  gem 'ruby-debug-base', '0.11.0', :platform => 'jruby'

  gem 'tty-prompt', :require => false
end

group(*ALL_TEST_ENVS) do
  gem 'rspec-core'
  gem 'rspec-rails'
  gem 'rspec-collection_matchers'
  gem 'rspec-http'
  gem 'rspec_junit_formatter'

  gem 'webmock'
  gem 'vcr'

  gem 'timecop'
end

group(*ALL_DEVELOPMENT_ENVS, *ALL_TEST_ENVS) do
  # Please note: We use the ent-search branch for swiftype-dev-services (and master for swiftype/website)
  gem 'swiftype-dev-services', :require => false, :git => 'git@github.com:swiftype/dev-services.git', :branch => 'ent-search'

  gem 'pry'

  gem 'factory_bot_rails', '~> 4.11.0', :require => false
  gem 'rb-fsevent', :require => false
  gem 'rb-inotify', :require => false
  gem 'listen', '~> 1.0'

  gem 'ejson'
end

#---------------------------------------------------------------------------------------------------
# Test dependencies for Rails environments (but not for the crawler)
#---------------------------------------------------------------------------------------------------
group :test do
  gem 'rack-parser', :require => 'rack/parser'
  gem 'rack-test', '~> 0.6.1'
  gem 'rswag-specs', :git => 'git@github.com:jetpackworkflow/rswag.git', :branch => 'allow_oas3_param_schema_array'
  # gem 'rswag-specs', '~> 2.3.1' # TODO - I want this back. Blocked by https://github.com/rswag/rswag/issues/317

  # Used for checking migration fixtures against ES state
  gem 'json-diff'
end
