# typed: strict
class Domain::Sofurry::PostPageParser
  extend T::Sig

  sig { params(page: String, require_logged_in: T::Boolean).void }
  def initialize(page, require_logged_in: true)
    @doc = T.let(Nokogiri.HTML(page), Nokogiri::HTML::Document)
    raise "not logged in" if require_logged_in && !logged_in?
  end

  sig { returns(T::Boolean) }
  def logged_in?
    @doc.css("input#LoginForm_sfLoginUsername").first.nil?
  end

  sig { returns(T::Boolean) }
  def post_not_found?
    @doc
      .css(".sflabel.pagetitle")
      .find { |elem| elem.text == "Not Found" }
      .present?
  end
end
