# typed: false
# frozen_string_literal: true
T.bind(self, T.all(Rake::DSL, Object))

namespace :twitter do
  desc "scan timeline of a user"
  task timeline: %i[set_logger_stdout environment] do |t, args|
    force_scan = ENV["force_scan"] || false
    name = ENV["name"] || raise("must provide name")
    Domain::Twitter::Job::UserTimelineTweetsJob.set(
      priority: -10,
    ).perform_later({ name: name, force_scan: force_scan })
    puts "timeline for #{name}"
  end

  task timeline_file: %i[set_logger_stdout environment] do
    file = ENV["file"]
    names = File.read(file).split("\n").map(&:strip).map(&:chomp)
    names.each do |name|
      Domain::Twitter::Job::UserTimelineTweetsJob.set(
        priority: -10,
      ).perform_later({ name: name, force_scan: false })
      puts "timeline for #{name}"
    end
  end
end
