# typed: true
class Domain::Twitter::Media < ReduxApplicationRecord
  self.table_name = "domain_twitter_medias"
  self.primary_key = :id

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

  belongs_to :tweet, class_name: "Domain::Twitter::Tweet"
  belongs_to :file, class_name: "HttpLogEntry", optional: true

  def error_status_count(num)
    self.state_detail["error_status_count_#{num}"] ||= 0
  end

  def inc_error_status_count(num)
    self.state_detail["error_status_count_#{num}"] ||= 0
    self.state_detail["error_status_count_#{num}"] += 1
  end
end
