1# frozen_string_literal: true
 2
 3require "value_semantics/monkey_patched"
 4require_relative "../admin_action"
 5
 6class AdminAction
 7	class ResetDeclines < AdminAction
 8		class Command
 9			def self.for(target_customer, **)
10				target_customer.declines.then { |declines|
11					AdminAction::ResetDeclines.for(
12						customer_id: target_customer.customer_id,
13						previous_value: declines
14					)
15				}
16			end
17		end
18
19		def customer_id
20			@attributes[:customer_id]
21		end
22
23		def previous_value
24			@attributes[:previous_value].to_i
25		end
26
27		def forward
28			CustomerFinancials.new(customer_id).set_declines(0).then { self }
29		end
30
31		# I could make sure here that they're still set to 0 in the reverse case, so
32		# I know there haven't been any declines since I ran the command, but I
33		# think I don't care actually, and I should just set it back to what it was
34		# and trust the human knows what they're doing
35		def reverse
36			CustomerFinancials.new(customer_id).set_declines(previous_value)
37				.then { self }
38		end
39
40		def to_s
41			"reset_declines(#{customer_id}): #{previous_value} -> 0"
42		end
43	end
44end