<commit_before>module PhotosHelper
  def crop_image_path(crop, full_size: false)
    photo_or_placeholder(crop, full_size: full_size)
  end

  def garden_image_path(garden, full_size: false)
    photo_or_placeholder(garden, full_size: full_size)
  end

  def planting_image_path(planting, full_size: false)
    photo_or_placeholder(planting, full_size: full_size)
  end

  def harvest_image_path(harvest, full_size: false)
    photo_or_placeholder(harvest, full_size: full_size)
  end

  def seed_image_path(seed, full_size: false)
    photo_or_placeholder(seed, full_size: full_size)
  end

  private

  def photo_or_placeholder(item, full_size: false)
    if item.default_photo.present?
      item_photo(item, full_size: full_size)
    else
      placeholder_image
    end
  end

  def item_photo(item, full_size:)
    photo = item.default_photo
    full_size ? photo.fullsize_url : photo.thumbnail_url
  end

  def placeholder_image<commit_msg>Revert "DRY the photos helper"<commit_after>module PhotosHelper
  def crop_image_path(crop, full_size: false)
    if crop.default_photo.present?
      photo = crop.default_photo
      full_size ? photo.fullsize_url : photo.thumbnail_url
    else
      placeholder_image
    end
  end

  def garden_image_path(garden, full_size: false)
    if garden.default_photo.present?
      photo = garden.default_photo
      full_size ? photo.fullsize_url : photo.thumbnail_url
    else
      placeholder_image
    end
  end

  def planting_image_path(planting, full_size: false)
    if planting.photos.present?
      photo = planting.photos.order(date_taken: :desc).first
      full_size ? photo.fullsize_url : photo.thumbnail_url
    else
      placeholder_image
    end
  end

  def harvest_image_path(harvest, full_size: false)
    if harvest.photos.present?
      photo = harvest.photos.order(date_taken: :desc).first
      full_size ? photo.fullsize_url : photo.thumbnail_url
    elsif harvest.planting.present?
      planting_image_path(harvest.planting, full_size: full_size)
    else
      placeholder_image
    end
  end

  def seed_image_path(seed, full_size: false)
    if seed.default_photo.present?
      photo = seed.default_photo
      full_size ? photo.fullsize_url : photo.thumbnail_url
    elsif seed.crop.default_photo.present?
      photo = seed.crop.default_photo
      full_size ? photo.fullsize_url : photo.thumbnail_url
    else
      placeholder_image
    end
  end

  private

  def placeholder_image
{'fraction_non_alphanumeric': 0.06701868399675061, 'fraction_numerical': 0.0, 'mean_word_length': 3.6736242884250476, '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': '3281053', 'n_tokens_mistral': 825, 'n_tokens_neox': 797, 'n_words': 164}