require 'notifications/client'

class CreateTapActivity < ApplicationJob
  class UnableToCreateSummaryDocumentActivity < StandardError; end

  rescue_from(CreateTapActivity::UnableToCreateSummaryDocumentActivity) do |exception|
    Bugsnag.notify(exception)
  end

  queue_as :default

  def perform(appointment_summary, owner)
    telephone_appointment = TelephoneAppointments::SummaryDocumentActivity.new(
      appointment_id: appointment_summary.reference_number,
      owner_uid: owner.uid,
      delivery_method: appointment_summary.requested_digital ? 'digital' : 'postal'
    )

    return if telephone_appointment.save

    raise UnableToCreateSummaryDocumentActivity, "Errors: #{telephone_appointment.errors.inspect}"
  end
end

require 'notifications/client'

class CreateTapActivity < ApplicationJob
  class UnableToCreateSummaryDocumentActivity < StandardError; end

  rescue_from(CreateTapActivity::UnableToCreateSummaryDocumentActivity) do |exception|
    Bugsnag.notify(exception)
  end

  queue_as :default

  def perform(appointment_summary, owner)
    telephone_appointment = TelephoneAppointments::SummaryDocumentActivity.new(
      appointment_id: appointment_summary.reference_number,
      owner_uid: owner.uid,
      delivery_method: appointment_summary.requested_digital ? 'digital' : 'postal'
    )

    return if telephone_appointment.save

    raise UnableToCreateSummaryDocumentActivity, <<~MESSAGE
      Appointment: #{appointment_summary.reference_number}
      Errors: #{telephone_appointment.errors.inspect}
    MESSAGE
  end
end

Include the appointment reference for debugging
Include the appointment reference for debugging

We currently have no way of knowing which actual appointment this
refers to so when these occur in production we are at a loss.
