module Recordings class ClubArchive def initialize(club, params: {}) @club = club @params = params end def stats Recordings::ClubStats.new(@club).call end def teams @club.teams.order(:name) end def filter_team_id @params[:team_id] end def filter_status @params[:status] end def recordings scope = Recording.for_club(@club) .not_deleted .includes(stream_session: { match: :team }) .order(recorded_at: :desc, created_at: :desc) scope = scope.where(team_id: filter_team_id) if filter_team_id.present? apply_status_filter(scope) end def filter_params { team_id: filter_team_id, status: filter_status }.compact end private def apply_status_filter(scope) case filter_status when "ready" scope.ready when "processing" scope.where(status: "processing") when "expired" scope.where( "recordings.status IN (?) OR (recordings.expires_at IS NOT NULL AND recordings.expires_at <= ?)", %w[expired failed], Time.current ) else scope end end end end