class CompetitionStage < ApplicationRecord
  belongs_to :competition

  has_many :competition_stage_sections, dependent: :destroy
  has_many :competition_entries, dependent: :destroy
  has_many :competition_scores, dependent: :destroy

  has_one :competition_module_md_content, dependent: :destroy
  has_one :chart_rule, dependent: :destroy

  def min_start_time
    competition_stage_sections.where("start_time is not null").pluck(:start_time).min
  end

  def max_end_time
    competition_stage_sections.where("end_time is not null").pluck(:end_time).max
  end
end