# frozen_string_literal: true

module FtcEvent
  class Qualifications
    attr_reader :event

    def initialize(event)
      @event = event
    end

    def name
      'Qualifications'
    end

    def match(match_number)
      Qualification.new(event, match_number)
    end

    def matches
      event.db.query('SELECT match FROM quals').map { |row| row['match'] }
    end

    def each_match
      return enum_for(:each_match) unless block_given?

      matches.each do |match_number|
        yield match(match_number)
      end

      nil
    end
  end
end
