# frozen_string_literal: true

class Plan
	def self.for(plan_name)
		plan = CONFIG[:plans].find { |p| p[:name] == plan_name }
		raise "No plan by that name" unless plan

		new(plan)
	end

	def initialize(plan)
		@plan = plan
	end

	def name
		@plan[:name]
	end

	def currency
		@plan[:currency]
	end

	def monthly_price
		BigDecimal.new(@plan[:monthly_price]) / 1000
	end

	def merchant_account
		CONFIG[:braintree][:merchant_accounts].fetch(currency) do
			raise "No merchant account for this currency"
		end
	end
end
