class Ecs::CourseAchievementMethodsController < Ecs::CourseBaseController
  def show
    include_associations = { ec_course_achievement_methods:
                               [:ec_course_evaluation, ec_achievement_evaluation_relates: :ec_course_evaluation_subitem] }
    @course_targets = current_course.ec_course_targets.includes(include_associations)
  end

  def create
    Ecs::CreateCourseAchievementMethodsService.call(current_course_target, create_params)
    render_ok
  end

  private

  def create_params
    params.permit(course_achievement_methods: [
      :id, :course_evaluation_id, :score, :percentage,
      course_evaluation_relates: %i[:subitem_id position]
    ])
  end

  def current_course_target
    @_current_course_target ||= current_course.ec_course_targets.find(params[:course_target_id])
  end
end