# frozen_string_literal: true

require_relative "backend_sgx"
require_relative "not_loaded"

class TrivialBackendSgxRepo
	def initialize(
		jid: CONFIG[:sgx],
		creds: CONFIG[:creds],
		component_jid: CONFIG[:component][:jid],
		**with
	)
		@jid = Blather::JID.new(jid)
		@creds = creds
		@component_jid = component_jid
		@with = with
	end

	def get(customer_id, tel: nil)
		BackendSgx.new(
			jid: @jid, creds: @creds,
			from_jid: Blather::JID.new("customer_#{customer_id}", @component_jid),
			ogm_url: NotLoaded.new(:ogm_url),
			fwd: NotLoaded.new(:fwd_timeout),
			transcription_enabled: NotLoaded.new(:transcription_enabled),
			registered?: tel ? ibr_for(tel) : NotLoaded.new(:registered?)
		).with(@with)
	end

protected

	def ibr_for(tel)
		ibr = Blather::Stanza::Iq::IBR.new
		ibr.registered = true
		ibr.phone = tel
		ibr
	end
end
