class ApplicationController < ActionController::API
  before_action :authenticate_user

  def current_user
    @current_user
  end

  private

  def authenticate_user
    code = request.headers['X-Transfer-Code'] || request.headers['HTTP_X_TRANSFER_CODE']
    @current_user = User.find_by(inheritance_code: code)
  end

  def bool? key, default: false
    return default if params[key].nil?

    s = params[key].to_s.strip.downcase
    if default
      !(s.in?(['0', 'false', 'off', 'no']))
    else
      s.in?(['', '1', 'true', 'on', 'yes'])
    end
  end
end
