class Cooperative::CompetitionSettingsController < Cooperative::BaseController
  def index
    @competition = current_competition
  end

  def basic_setting
    Admins::CompetitionBasicSettingService.call(current_competition, basic_form_params)
    render_ok
  end

  def nav_setting
    Admins::CompetitionNavSettingService.call(current_competition, nav_form_params)
    render_ok
  end

  private

  def current_competition
    @_current_competition ||= current_laboratory.competitions.find(params[:competition_id])
  end

  def basic_form_params
    params.permit(:identifier, :name, :sub_title, :start_time, :end_time, :mode,
                  :identifier, :bonus, :awards_count, :description, :course_id, :teach_start_time,
                  :teach_end_time, sponsor_schools: [], region_schools: [], manager_ids: [])
  end

  def nav_form_params
    params.permit(:enroll_end_time,
                  competition_staffs: %i[category minimum maximum mutiple_limited],
                  navbar: %i[module_type module_id name hidden position url])
  end
end