class SubmitHubspotTaskRequestFormJob < ApplicationJob
  queue_as :default

  def perform(user_email, taskme_url)
    hubspot_task_request_form_guid = ENV["HUBSPOT_TASK_REQUEST_FORM_GUID"]
    return unless hubspot_task_request_form_guid.present?

    submission_params = {
      email: user_email, 
      taskme_url: taskme_url
    }

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

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