# typed: strict
class Domain::User::InkbunnyUser < Domain::User
  aux_table :inkbunny

  belongs_to :deep_update_log_entry,
             class_name: "::HttpLogEntry",
             optional: true

  belongs_to :shallow_update_log_entry,
             class_name: "::HttpLogEntry",
             optional: true

  has_created_posts! Domain::Post::InkbunnyPost
  has_faved_posts! Domain::Post::InkbunnyPost

  validates :ib_id, presence: true
  validates :name, presence: true
  validates :state, presence: true, inclusion: { in: %w[ok error] }

  after_initialize do
    self.state ||= "ok"
    self.ib_detail_raw ||= {}
  end

  sig { override.returns([String, Symbol]) }
  def self.param_prefix_and_attribute
    ["ib", :name]
  end

  sig { override.returns(String) }
  def self.view_prefix
    "ib"
  end

  sig { override.returns(Domain::DomainType) }
  def self.domain_type
    Domain::DomainType::Inkbunny
  end

  sig { override.returns(String) }
  def account_status_for_view
    "ok"
  end

  sig { override.returns(String) }
  def description_html_base_domain
    "inkbunny.net"
  end

  sig { override.returns(String) }
  def site_name_for_view
    "Inkbunny"
  end

  sig { override.returns(T.nilable(String)) }
  def external_url_for_view
    "https://inkbunny.net/#{name}" if name.present?
  end

  sig { override.returns(T.nilable(String)) }
  def name_for_view
    name
  end

  sig { override.returns(T::Array[String]) }
  def names_for_search
    [name].compact
  end

  sig { returns(T::Boolean) }
  def due_for_gallery_scan?
    if at = self.scanned_gallery_at
      at < 1.month.ago
    else
      true
    end
  end
end
