require 'http.rb'
  
class WebhookEventWorker
  include Sidekiq::Worker
  sidekiq_options :queue => :webhook, :retry => 3, :backtrace => true
 
  def perform(notification_group, event, payload, ln_id, org_id, is_test_event=false)
    if notification_group.webhook_type?
      notification_group.webhook_endpoints.each do |webhook_endpoint|
        webhook_event = WebhookEvent.create(webhook_endpoint_id: webhook_endpoint.id, event: event, payload: payload, location_network_id: ln_id, organisation_id: org_id, is_test: is_test_event)
        p "[WEBHOOK-ENDPOINT-WORKER][#{webhook_endpoint.id}] :: Pushing to #{webhook_endpoint.url} :: [PAYLOAD] :: #{payload}"
        WebhookWorker.perform_async(webhook_event.id)
      end
    end
  end
end