class Admin::Legacy::Student::Students::Indiana::ChoicesController <
  Admin::Legacy::Student::Controller
  def index
    if student_id
      render_success :ok, json: choice_service.index_by_student(student_id)
    else
      render_success :ok, json: []
    end
  end

  def show
    render_success :ok, json: choice_service.find_record(params[:id])
  end

  def destroy
    if params[:id]
      choice_service.delete(params[:id])
      render_success :ok, json: { success: true }
    else
      render_error :unprocessable_entity, json: { success: false }
    end
  end

  private
    def student
      current_school.students.find_by(id: params[:student_id])
    end

    def student_id
      @student_id ||= student&.state_number&.number
    end

    def choice_service
      EdFi::Indiana::Sandbox::StudentEducationResponsibilityService.new(
        current_school_year.id,
        student: student
      )
    end
end
