1# frozen_string_literal: true
 2
 3class AdminAction
 4	class CancelCustomer
 5		def self.cancel_stanza
 6			m = Blather::Stanza::Message.new
 7			m.from = CONFIG[:notify_from]
 8			m.body = "Your JMP account has been cancelled."
 9			m
10		end
11
12		def self.call(customer, customer_repo:, **)
13			raise "Customer not registered" unless customer.registered?
14
15			m = cancel_stanza
16			customer.stanza_to(m).then {
17				EMPromise.all([
18					Churnbuster.new.cancellation(customer),
19					customer.stanza_to(Blather::Stanza::Iq::IBR.new(:set).tap(&:remove!)),
20					customer.deregister!, customer_repo.disconnect_tel(customer)
21				])
22			}
23		end
24	end
25end