# frozen_string_literal: true


module TagRepr
  BASE = { only: [:id, :category, :post_count, :created_at, :updated_at, :deprecated_at],
           methods: [:name, :has_wiki, :material_id, :has_deerjikists] }.freeze

  module_function

  def base tag
    tag.as_json(BASE).merge(aliases: tag.snapshot_aliases,
                            parents: tag.parents.map { _1.as_json(BASE) })
  end

  def inline tag
    tag.as_json(BASE).merge(aliases: [], parents: [])
  end

  def many(tags) = tags.map { |t| base(t) }
end
