class SubmitHubspotFormJob < ApplicationJob
  queue_as :default

  def perform(email, company_name, additional_params = {})
    hubspot_form_guid = ENV["HUBSPOT_FORM_GUID"]
    return unless hubspot_form_guid.present?

    submission_params = {
      email: email, 
      company: company_name
    }.merge(additional_params)

    form = Hubspot::Form.new("guid" => hubspot_form_guid)
    is_form_sumitted = form.submit(submission_params)

    raise StandardError.new "Failed to submit the hubspot form data: #{is_form_sumitted}" unless is_form_sumitted
  end
end
