<commit_before>class Stacks::Services::ProxyVHost
  attr_accessor :aliases
  attr_accessor :cert
  attr_reader :properties
  attr_reader :proxy_pass_rules
  attr_reader :redirects
  attr_reader :service
  attr_reader :type
  attr_reader :environment

  def initialize(virtual_proxy_service, fqdn, service, environment, type = 'default', &block)
    @aliases = []
    @add_default_aliases = true
    @cert = 'wildcard_timgroup_com'
    @properties = {}
    @proxy_pass_rules = {}
    @redirects = []
    @service = service
    @type = type
    @fqdn = fqdn
    @environment = environment
    @virtual_proxy_service = virtual_proxy_service

    instance_eval(&block) if block
  end

  # XXX looks like this method is never used
  def with_redirect(redirect_fqdn)
    @redirects << redirect_fqdn
  end

  def add_pass_rule(path, config_hash)
    @proxy_pass_rules[path] = config_hash
    if config_hash.key? :environment
      @virtual_proxy_service.depend_on config_hash[:service], config_hash[:environment]
    else
      @virtual_proxy_service.depend_on config_hash[:service], @environment
    end
  end

  def add_properties(properties)
    @properties.merge!(properties)
  end

  def aliases(location)
    aliases = Set.new
    if @add_default_aliases
      aliases << @virtual_proxy_service.vip_fqdn(:front, location)
      aliases << @virtual_proxy_service.vip_fqdn(:prod, location)
    end
    aliases.merge(@aliases)
    aliases.delete(fqdn(location))
    aliases.to_a
  end

  def fqdn(location)
    if @fqdn.nil?
      @virtual_proxy_service.vip_fqdn(:front, location)
    else
      @fqdn
    end
  end

  def proxy_pass_rules(location)
    Hash[@proxy_pass_rules.map do |path, config_hash|
      service_environment = environment
      service_environment = config_hash[:environment] if config_hash.key?(:environment)
      service = @virtual_proxy_service.find_virtual_service(config_hash[:service], service_environment)
      [path, "http://#{service.vip_fqdn(:prod, location)}:8000"]
    end]
  end

  def to_proxy_config_hash(location)
    [fqdn(location), {<commit_msg>rpearce: Vain attempt to sort the aliases<commit_after>class Stacks::Services::ProxyVHost
  attr_accessor :aliases
  attr_accessor :cert
  attr_reader :properties
  attr_reader :proxy_pass_rules
  attr_reader :redirects
  attr_reader :service
  attr_reader :type
  attr_reader :environment

  def initialize(virtual_proxy_service, fqdn, service, environment, type = 'default', &block)
    @aliases = []
    @add_default_aliases = true
    @cert = 'wildcard_timgroup_com'
    @properties = {}
    @proxy_pass_rules = {}
    @redirects = []
    @service = service
    @type = type
    @fqdn = fqdn
    @environment = environment
    @virtual_proxy_service = virtual_proxy_service

    instance_eval(&block) if block
  end

  # XXX looks like this method is never used
  def with_redirect(redirect_fqdn)
    @redirects << redirect_fqdn
  end

  def add_pass_rule(path, config_hash)
    @proxy_pass_rules[path] = config_hash
    if config_hash.key? :environment
      @virtual_proxy_service.depend_on config_hash[:service], config_hash[:environment]
    else
      @virtual_proxy_service.depend_on config_hash[:service], @environment
    end
  end

  def add_properties(properties)
    @properties.merge!(properties)
  end

  def aliases(location)
    aliases = Set.new
    if @add_default_aliases
      aliases << @virtual_proxy_service.vip_fqdn(:front, location)
      aliases << @virtual_proxy_service.vip_fqdn(:prod, location)
    end
    aliases.merge(@aliases)
    aliases.delete(fqdn(location))
    aliases.to_a.sort
  end

  def fqdn(location)
    if @fqdn.nil?
      @virtual_proxy_service.vip_fqdn(:front, location)
    else
      @fqdn
    end
  end

  def proxy_pass_rules(location)
    Hash[@proxy_pass_rules.map do |path, config_hash|
      service_environment = environment
      service_environment = config_hash[:environment] if config_hash.key?(:environment)
      service = @virtual_proxy_service.find_virtual_service(config_hash[:service], service_environment)
      [path, "http://#{service.vip_fqdn(:prod, location)}:8000"]
    end]
  end

  def to_proxy_config_hash(location)
    [fqdn(location), {
{'fraction_non_alphanumeric': 0.09331111640085694, 'fraction_numerical': 0.0019043084979766722, 'mean_word_length': 4.050480769230769, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3609774', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1366, 'n_words': 270}