<commit_before># V2 Version of Channels list
#
# Each channel is an array:
# [
#   channel_identifier (string),
#   verified (boolean),
#   excluded (boolean),
#   wallet address
#   site_banner details
# ]
#
# ex.
# [
#   ["brave.com", true, false, {title: 'Hello', description: 'world'...}, 1234-abcd-5678-efgh],
#   ["google.com", false, true, {}, 1234-abcd-5678-efgh],
#   ["us.gov", false, false, {}, 1234-abcd-5678-efgh]
# ]

class JsonBuilders::ChannelsJsonBuilderV2
  def initialize
    require "publishers/excluded_channels"
    @excluded_channel_ids = Publishers::ExcludedChannels.brave_publisher_id_list
    @excluded_verified_channel_ids = []
    @channels = []
  end

  def build
    joined_verified_channels.each do |verified_channels|
      verified_channels.find_each do |verified_channel|
        include_verified_channel(verified_channel)
      end
    end
    append_excluded
    @channels.to_json
  end

  private

  def joined_verified_channels
    [
      Channel.verified.site_channels.includes(:site_banner).includes(publisher: :site_banners),
      Channel.verified.youtube_channels.includes(:site_banner).includes(publisher: :site_banners),
      Channel.verified.twitch_channels.includes(:site_banner).includes(publisher: :site_banners),
      Channel.verified.twitter_channels.includes(:site_banner).includes(publisher: :site_banners),
      Channel.verified.vimeo_channels.includes(:site_banner).includes(publisher: :site_banners),
      Channel.verified.reddit_channels.includes(:site_banner).includes(publisher: :site_banners),
      Channel.verified.github_channels.includes(:site_banner).includes(publisher: :site_banners),
    ]
  end

  def include_verified_channel(verified_channel)
    # Skip if channel is on exclusion list
    return if @excluded_channel_ids.include?(verified_channel.details.channel_identifier)
    # Skip if channel publisher has not yet KYC'd
    return unless verified_channel.publisher&.uphold_connection&.is_member
    @channels.push([
      verified_channel.details.channel_identifier,
      true,
      false,
      "00000000-0000-0000-0000-000000000000",
      site_banner_details(verified_channel),
    ])
  end

  def site_banner_details(channel)<commit_msg>Only turn on home address for staging and dev<commit_after># V2 Version of Channels list
#
# Each channel is an array:
# [
#   channel_identifier (string),
#   verified (boolean),
#   excluded (boolean),
#   wallet address
#   site_banner details
# ]
#
# ex.
# [
#   ["brave.com", true, false, {title: 'Hello', description: 'world'...}, 1234-abcd-5678-efgh],
#   ["google.com", false, true, {}, 1234-abcd-5678-efgh],
#   ["us.gov", false, false, {}, 1234-abcd-5678-efgh]
# ]

class JsonBuilders::ChannelsJsonBuilderV2
  def initialize
    require "publishers/excluded_channels"
    @excluded_channel_ids = Publishers::ExcludedChannels.brave_publisher_id_list
    @excluded_verified_channel_ids = []
    @channels = []
  end

  def build
    joined_verified_channels.each do |verified_channels|
      verified_channels.find_each do |verified_channel|
        include_verified_channel(verified_channel)
      end
    end
    append_excluded
    @channels.to_json
  end

  private

  def joined_verified_channels
    [
      Channel.verified.site_channels.includes(:site_banner).includes(publisher: :site_banners),
      Channel.verified.youtube_channels.includes(:site_banner).includes(publisher: :site_banners),
      Channel.verified.twitch_channels.includes(:site_banner).includes(publisher: :site_banners),
      Channel.verified.twitter_channels.includes(:site_banner).includes(publisher: :site_banners),
      Channel.verified.vimeo_channels.includes(:site_banner).includes(publisher: :site_banners),
      Channel.verified.reddit_channels.includes(:site_banner).includes(publisher: :site_banners),
      Channel.verified.github_channels.includes(:site_banner).includes(publisher: :site_banners),
    ]
  end

  def include_verified_channel(verified_channel)
    # Skip if channel is on exclusion list
    return if @excluded_channel_ids.include?(verified_channel.details.channel_identifier)
    # Skip if channel publisher has not yet KYC'd
    return unless verified_channel.publisher&.uphold_connection&.is_member
    @channels.push([
      verified_channel.details.channel_identifier,
      true,
      false,
      Rails.env.development? || Rails.env.staging? ? verified_channel.publisher.uphold_connection.address : "00000000-0000-0000-0000-000000000000",
      site_banner_details(verified_channel),
    ])
  end

  def site_banner_details(channel)
{'fraction_non_alphanumeric': 0.10885689354275742, 'fraction_numerical': 0.02530541012216405, 'mean_word_length': 4.524096385542169, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '974344', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1461, 'n_words': 236}