competition = current_competition
json.extract! competition, :id, :name, :sub_title, :identifier

json.start_time competition.display_start_time
json.end_time competition.display_end_time
json.enroll_end_time competition.display_enroll_end_time

json.images do
  json.array! competition.attachments, partial: 'attachments/attachment_simple', as: :attachment
end

json.competition_stages do
  stages = competition.competition_stages.includes(competition_stage_sections: :competition_entries)
  json.array! stages.each do |stage|
    json.extract! stage, :id, :name

    json.sections do
      json.array! stage.competition_stage_sections.each do |section|
        json.extract! section, :id, :name

        decorator_section = ActiveDecorator::Decorator.instance.decorate(section)
        json.start_time decorator_section.display_start_time
        json.end_time decorator_section.display_end_time

        is_start = section.start_time > Time.now
        json.entries do
          json.array! section.competition_entries.each do |entry|
            json.extract! entry, :id, :name

            json.url is_start ? entry.url : ''
          end
        end
      end
    end
  end
end