# typed: true
class Domain::Twitter::Job::TwitterJobBase < Scraper::JobBase
  discard_on ActiveJob::DeserializationError

  def self.http_factory_method
    :get_twitter_http_client
  end

  def find_or_create_user_from_args(args)
    if args[:user]
      args[:user]
    elsif args[:tw_id].present?
      Domain::Twitter::User.find_or_initialize_by(tw_id: args[:tw_id])
    elsif args[:name].present?
      Domain::Twitter::User.find_or_initialize_by(name: args[:name])
    else
      fatal_error("arg 'name' or 'tw_id' is required if arg 'user' is nil")
    end
  end
end
