class Api::ShopsController < Api::ApiController
	skip_before_action :authenticate, only: [:index, :show]
	skip_before_action :set_current_tenant_by_subdomain_or_name, only: [:index, :show]

	def index
		@shops = Shop.select('id, logo, name, shop_code').where.not(cloud_url: nil).all
	end

	def show
		@shop = Shop.find_by_shop_code(params[:id])
	end

	def get_tax_profiles
		@inclusive_tax, @exclusive_tax = TaxProfile.calculate_tax("online_order")
	end

	def lookup_domain
		if ["index", "show"].include? action_name
			if ENV["SERVER_CODE"] == "cloud" && request.subdomains.last && request.subdomains.last != "www"
	      @license = cache_license(ENV["SX_PROVISION_URL"], request.host) # request.subdomain.downcase
	      if (!@license.nil?)
	        logger.info "Location - " + @license.dbschema
	        ActiveRecord::Base.establish_connection(website_connection(@license))
	      else
	        logger.info 'License is nil'
	        not_found
	      end
	    elsif ENV["SERVER_MODE"] == "application" || (request.subdomains.last && request.subdomains.last != "www")
	      not_found unless check_license(request.host)
	    end
		else
			super
		end
	end
end
