# typed: strict
class Domain::User::E621User < Domain::User
  aux_table :e621

  enum :scanned_favs_status, { ok: "ok", error: "error" }, prefix: :scanned_favs

  has_many :uploaded_posts,
           class_name: "::Domain::Post::E621Post",
           foreign_key: :uploader_user_id,
           inverse_of: :uploader_user

  validates :scanned_favs_status,
            inclusion: {
              in: %w[ok error],
              if: :scanned_favs_status?,
            }
  validates :e621_id, presence: true
  validates :name, length: { minimum: 1 }, allow_nil: false

  has_faved_posts! Domain::Post::E621Post

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

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

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

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

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

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

  sig { override.returns(T.nilable(String)) }
  def external_url_for_view
    "https://e621.net/users/#{e621_id}" if e621_id.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.nilable(::String)) }
  def url_name
    if name = self.name
      name.gsub(" ", "_")
    end
  end
end
