# typed: false
class Domain::Twitter::User < ReduxApplicationRecord
  self.table_name = "domain_twitter_users"

  has_many :tweets,
           class_name: "Domain::Twitter::Tweet",
           foreign_key: "author_id",
           primary_key: "tw_id"

  has_many :medias, through: :tweets

  enum :state, %i[ok error]
  validates_presence_of(:name)
  after_initialize do
    self.state ||= "ok"
    self.state_detail ||= {}
    self.raw_data ||= {}
  end

  def tweets_protected_error_proxies
    self.state_detail["tweets_protected_error_proxies"] ||= []
    self.state_detail["tweets_protected_error_proxies"]
  end

  def due_for_timeline_tweets_scan?
    scanned_timeline_at.nil? || scanned_timeline_at < 1.hour.ago
  end
end
