<commit_before>module Presenters
  class DownstreamPresenter
    def self.present(content_item, state_fallback_order:)
      link_set = LinkSet.find_by(content_id: content_item.content_id)
      new(content_item, link_set, state_fallback_order: state_fallback_order).present
    end

    def initialize(content_item, link_set, state_fallback_order:)
      self.content_item = content_item
      self.link_set = link_set
      self.state_fallback_order = state_fallback_order
    end

    def present
      symbolized_attributes
        .slice(*content_item.class::TOP_LEVEL_FIELDS)
        .merge(first_published_at)
        .merge(public_updated_at)
        .merge(links)
        .merge(access_limited)
        .merge(base_path)
        .merge(locale)
        .merge(withdrawal_notice)
    end

  private

    attr_accessor :content_item, :link_set, :state_fallback_order

    def symbolized_attributes
      content_item.as_json.symbolize_keys
    end

    def links
      return {} unless link_set
      {
        links: link_set_presenter.links,
        expanded_links: expanded_link_set_presenter.links
      }
    end

    def access_limited
      return {} unless access_limit
      {
        access_limited: {
          users: access_limit.users
        }
      }
    end

    def link_set_presenter
      Presenters::Queries::LinkSetPresenter.new(link_set)
    end

    def expanded_link_set_presenter
      Presenters::Queries::ExpandedLinkSet.new(
        link_set: link_set,
        state_fallback_order: state_fallback_order,
      )
    end

    def access_limit
      @access_limit ||= AccessLimit.find_by(content_item: content_item)
    end

    def web_content_item
      @web_content_item ||= WebContentItem.new(content_item)
    end

    def first_published_at
      if content_item.first_published_at.present?
        { first_published_at: content_item.first_published_at.iso8601 }
      else
        {}
      end
    end

    def public_updated_at
      return {} unless content_item.public_updated_at.present?
      { public_updated_at: content_item.public_updated_at.iso8601 }
    end

    def base_path
      { base_path: web_content_item.base_path }
    end

    def locale
      { locale: web_content_item.locale }
    end

    def withdrawal_notice<commit_msg>Use current locale in DownstreamPresenter.<commit_after>module Presenters
  class DownstreamPresenter
    def self.present(content_item, state_fallback_order:)
      link_set = LinkSet.find_by(content_id: content_item.content_id)
      new(content_item, link_set, state_fallback_order: state_fallback_order).present
    end

    def initialize(content_item, link_set, state_fallback_order:)
      self.content_item = content_item
      self.link_set = link_set
      self.state_fallback_order = state_fallback_order
    end

    def present
      symbolized_attributes
        .slice(*content_item.class::TOP_LEVEL_FIELDS)
        .merge(first_published_at)
        .merge(public_updated_at)
        .merge(links)
        .merge(access_limited)
        .merge(base_path)
        .merge(locale)
        .merge(withdrawal_notice)
    end

  private

    attr_accessor :content_item, :link_set, :state_fallback_order

    def symbolized_attributes
      content_item.as_json.symbolize_keys
    end

    def links
      return {} unless link_set
      {
        links: link_set_presenter.links,
        expanded_links: expanded_link_set_presenter.links
      }
    end

    def access_limited
      return {} unless access_limit
      {
        access_limited: {
          users: access_limit.users
        }
      }
    end

    def link_set_presenter
      Presenters::Queries::LinkSetPresenter.new(link_set)
    end

    def expanded_link_set_presenter
      Presenters::Queries::ExpandedLinkSet.new(
        link_set: link_set,
        state_fallback_order: state_fallback_order,
        locale_fallback_order: locale_fallback_order
      )
    end

    def access_limit
      @access_limit ||= AccessLimit.find_by(content_item: content_item)
    end

    def web_content_item
      @web_content_item ||= WebContentItem.new(content_item)
    end

    def locale_fallback_order
      [web_content_item.locale, ContentItem::DEFAULT_LOCALE].uniq
    end

    def first_published_at
      if content_item.first_published_at.present?
        { first_published_at: content_item.first_published_at.iso8601 }
      else
        {}
      end
    end

    def public_updated_at
      return {} unless content_item.public_updated_at.present?
      { public_updated_at: content_item.public_updated_at.iso8601 }
    end

    def base_path
      { base_path: web_content_item.base_path }
    end

    def locale
      { locale: web_content_item.locale }
    end

    def withdrawal_notice
{'fraction_non_alphanumeric': 0.06280193236714976, 'fraction_numerical': 0.0033606385213190504, 'mean_word_length': 2.815705128205128, 'pattern_counts': {'":': 0, '<': 3, '<?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': '234689', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1467, 'n_words': 246}