# frozen_string_literal: true

require 'sinatra/base'
require 'sequel'
require 'sqlite3'

require_relative 'config'

# Load configuration from environment config file
$conf = Config.new()

# Load the Sequel timestamps plugin
Sequel::Model.plugin(:timestamps)
# Initialize Sequel gem for database actions
DB = Sequel.connect(adapter: $conf.get('database.adapter'), database: $conf.get('database.database'))

# Load in routes (must happen after Sequel is loaded!)
require_relative 'controllers/api1'
require_relative 'controllers/benchmark'
require_relative 'controllers/hardware'
require_relative 'controllers/index'
require_relative 'controllers/reports'
require_relative 'controllers/result'
require_relative 'controllers/test'

# GameData - main app that gets launched
#   - inherits from Sinatra::Base to instantiate the server
#   - sets up some base app configuration
#   - registers route classes with the base app
class GameData < Sinatra::Base

  enable :sessions

  # Set up static file serving
  enable :static
  set :public_folder, File.join(__dir__, '/../public')

  use IndexController
  use HardwareController
  use BenchmarkController
  use TestController
  use ResultController
  use ReportsController
  use APIv1Controller

end
