json.course_targets @course_targets,
                    partial: 'ecs/course_targets/shared/ec_course_target_with_achievement_methods',
                    as: :ec_course_target
json.course_targets do
  json.array! @course_targets do |course_target|
    json.extract! course_target, :id, :position, :content

    json.course_achievement_methods do
      json.array! course_target.ec_course_achievement_methods do |achievement_method|
        evaluation = achievement_method.ec_course_evaluation
        json.extract! achievement_method, :id, :score, :percentage

        json.course_evaluation do
          json.partial! 'ecs/course_evaluations/shared/ec_course_evaluation_only', ec_course_evaluation: evaluation
        end

        json.course_evaluation_relates do
          json.array! achievement_method.ec_achievement_evaluation_relates do |relate|
            json.extract! relate, :id, :position, :ec_course_evaluation_subitem_id

            subitem = relate.ec_course_evaluation_subitem
            if evaluation.is_course_type?
              json.name subitem&.name
            else
              json.name subitem&.name ? "#{evaluation.name}（#{relate.position}）:#{subitem&.name}" : "#{evaluation.name}（#{relate.position}）"
            end
          end
        end
      end
    end
  end
end