class TagVersioning
  def self.record! tag, event_type:, created_by_user:
    if tag.nico?
      NicoTagVersionRecorder.record!(tag:, event_type:, created_by_user:)
    else
      TagVersionRecorder.record!(tag:, event_type:, created_by_user:)
    end
  end

  def self.ensure_snapshot! tag, created_by_user:
    if tag.nico?
      return if tag.nico_tag_versions.exists?

      NicoTagVersionRecorder.record!(tag:, event_type: :create, created_by_user:)
    else
      return if tag.tag_versions.exists?

      TagVersionRecorder.record!(tag:, event_type: :create, created_by_user:)
    end
  end

  def self.record_tag_snapshot! tag, created_by_user:
    event_type =
        if tag.nico?
          tag.nico_tag_versions.exists? ? :update : :create
        else
          tag.tag_versions.exists? ? :update : :create
        end

    record!(tag, event_type:, created_by_user:)
  end

  def self.record_tag_snapshots! tags, created_by_user:
    tags.each do |tag|
      record_tag_snapshot!(tag, created_by_user:)
    end
  end
end
