class TheatreWatchingUser < ApplicationRecord
  self.primary_key = :theatre_id, :user_id

  belongs_to :theatre
  belongs_to :user

  scope :active, -> { where('expires_at >= ?', Time.current) }
  scope :expired, -> { where('expires_at < ?', Time.current) }

  def active? = expires_at >= Time.current

  def refresh! = update!(expires_at: 30.seconds.from_now)
end
