1# frozen_string_literal: true
2
3require "value_semantics/monkey_patched"
4require_relative "proxied_jid"
5
6class LegacyCustomer
7 attr_reader :jid, :tel
8
9 def initialize(jid, tel)
10 @jid = jid
11 @tel = tel
12 end
13
14 def customer_id
15 nil
16 end
17
18 def info
19 EMPromise.resolve(nil).then do
20 Info.new(jid: jid, tel: tel)
21 end
22 end
23
24 def admin_info
25 EMPromise.all([
26 info,
27 api
28 ]).then do |info, api|
29 AdminInfo.new(info: info, api: api)
30 end
31 end
32
33 def api
34 API.for(self)
35 end
36
37 class Info
38 value_semantics do
39 jid ProxiedJID, coerce: ProxiedJID.method(:new)
40 tel String
41 end
42
43 def fields
44 [
45 { var: "JID", value: jid.unproxied.to_s },
46 { var: "Phone Number", value: tel }
47 ]
48 end
49 end
50
51 class AdminInfo
52 value_semantics do
53 info Info
54 api API
55 end
56
57 def fields
58 info.fields + [
59 { var: "Account Status", value: "Legacy" },
60 { var: "Cheo JID", value: info.jid.to_s },
61 { var: "API", value: api.to_s }
62 ]
63 end
64 end
65end