require 'securerandom'
class GatewaysController < ApplicationController
  before_action :authenticate
  skip_before_action :authenticate, only: [:status]

  def status
    render json: { message: 'App is up and running' }, status: :ok
  end

  def call
    request_values = {
      id: SecureRandom.hex(5),
      verb: request.method,
      path: request.fullpath,
      remote_addr: request.remote_addr,
      query_string: request.query_string,
      url_pattern: get_route_pattern}
    # NotificationWorker.perform_async(request_values, params_permit)
    response = RequestPipeline.new(request_values, params_permit).execute
    render json: response[:body], headers: response[:headers], status: response[:status]
  end

  private

  def get_route_pattern
    Rails.application.routes.router.recognize(request) { |route| return route.path.spec.to_s }
  end
end
