class VideoReleaseConfirmation < ApplicationRecord
  belongs_to :video
  belongs_to :releasable, polymorphic: true
  belongs_to :file_info, optional: true

  scope :order_by_ranked_release_type, -> { order(ReleaseRankOrder.new.sql) }

  def appears_at
    Timecode.from_seconds(time_elapsed.to_f).to_s
  end

  private

  class ReleaseRankOrder
    def sql
      attribute = "releasable_type"
      types = [TalentRelease, AppearanceRelease, LocationRelease, AcquiredMediaRelease, MaterialRelease, MusicRelease]
      CustomRankOrder.new(attribute, types).sql
    end
  end
end
