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

namespace :ib do
  desc "run a single e621 posts index job"
  task latest_posts_job: :environment do
    Domain::Inkbunny::Job::LatestPostsJob.set(priority: -10).perform_later({})
  end

  desc "set auth credentials"
  task set_auth: :environment do
    username = nil
    password = nil

    while username.blank?
      print "enter username: "
      username = $stdin.gets.chomp
    end

    while password.blank?
      print "enter password: "
      password = $stdin.gets.chomp
    end

    GlobalState
      .find_or_create_by(key: "inkbunny-username")
      .update!(value: username) { |gs| gs.value_type = :string }
    GlobalState
      .find_or_create_by(key: "inkbunny-password")
      .update!(value: password) { |gs| gs.value_type = :password }

    puts "auth credentials set to #{username} / #{password}"
  end
end
