<commit_before>package org.stepik.android.view.step_quiz.ui.factory

import androidx.fragment.app.Fragment
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import org.stepic.droid.configuration.RemoteConfig
import org.stepic.droid.persistence.model.StepPersistentWrapper
import org.stepic.droid.util.AppConstants
import org.stepik.android.domain.lesson.model.LessonData
import org.stepik.android.view.step_quiz_choice.ui.fragment.ChoiceStepQuizFragment
import org.stepik.android.view.step_quiz_code.ui.fragment.CodeStepQuizFragment
import org.stepik.android.view.step_quiz_fill_blanks.ui.fragment.FillBlanksStepQuizFragment
import org.stepik.android.view.step_quiz_matching.ui.fragment.MatchingStepQuizFragment
import org.stepik.android.view.step_quiz_sorting.ui.fragment.SortingStepQuizFragment
import org.stepik.android.view.step_quiz_sql.ui.fragment.SqlStepQuizFragment
import org.stepik.android.view.step_quiz_text.ui.fragment.TextStepQuizFragment
import org.stepik.android.view.step_quiz_unsupported.ui.fragment.UnsupportedStepQuizFragment
import org.stepik.android.view.step_quiz_pycharm.ui.fragment.PyCharmStepQuizFragment
import org.stepik.android.view.step_quiz_review.ui.fragment.StepQuizReviewFragment
import org.stepik.android.view.step_quiz_table.ui.fragment.TableStepQuizFragment
import javax.inject.Inject

class StepQuizFragmentFactoryImpl
@Inject
constructor(
    private val firebaseRemoteConfig: FirebaseRemoteConfig
) : StepQuizFragmentFactory {
    override fun createStepQuizFragment(stepPersistentWrapper: StepPersistentWrapper, lessonData: LessonData): Fragment {
        val instructionType =
            stepPersistentWrapper.step.instructionType.takeIf { stepPersistentWrapper.step.actions?.doReview != null }

        val blockName = stepPersistentWrapper.step.block?.name

        return if (instructionType != null &&
            firebaseRemoteConfig.getBoolean(RemoteConfig.IS_PEER_REVIEW_ENABLED) &&
            blockName in StepQuizReviewFragment.supportedQuizTypes &&
            !lessonData.lesson.isTeacher) {
            StepQuizReviewFragment.newInstance(stepPersistentWrapper.step.id, instructionType)
        } else {
            getDefaultQuizFragment(stepPersistentWrapper)
        }<commit_msg>APPS-3193: routing to teacher review fragment<commit_after>package org.stepik.android.view.step_quiz.ui.factory

import androidx.fragment.app.Fragment
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import org.stepic.droid.configuration.RemoteConfig
import org.stepic.droid.persistence.model.StepPersistentWrapper
import org.stepic.droid.util.AppConstants
import org.stepik.android.domain.lesson.model.LessonData
import org.stepik.android.view.step_quiz_choice.ui.fragment.ChoiceStepQuizFragment
import org.stepik.android.view.step_quiz_code.ui.fragment.CodeStepQuizFragment
import org.stepik.android.view.step_quiz_fill_blanks.ui.fragment.FillBlanksStepQuizFragment
import org.stepik.android.view.step_quiz_matching.ui.fragment.MatchingStepQuizFragment
import org.stepik.android.view.step_quiz_sorting.ui.fragment.SortingStepQuizFragment
import org.stepik.android.view.step_quiz_sql.ui.fragment.SqlStepQuizFragment
import org.stepik.android.view.step_quiz_text.ui.fragment.TextStepQuizFragment
import org.stepik.android.view.step_quiz_unsupported.ui.fragment.UnsupportedStepQuizFragment
import org.stepik.android.view.step_quiz_pycharm.ui.fragment.PyCharmStepQuizFragment
import org.stepik.android.view.step_quiz_review.ui.fragment.StepQuizReviewFragment
import org.stepik.android.view.step_quiz_review.ui.fragment.StepQuizReviewTeacherFragment
import org.stepik.android.view.step_quiz_table.ui.fragment.TableStepQuizFragment
import javax.inject.Inject

class StepQuizFragmentFactoryImpl
@Inject
constructor(
    private val firebaseRemoteConfig: FirebaseRemoteConfig
) : StepQuizFragmentFactory {
    override fun createStepQuizFragment(stepPersistentWrapper: StepPersistentWrapper, lessonData: LessonData): Fragment {
        val instructionType =
            stepPersistentWrapper.step.instructionType.takeIf { stepPersistentWrapper.step.actions?.doReview != null }

        val blockName = stepPersistentWrapper.step.block?.name

        return if (instructionType != null && firebaseRemoteConfig.getBoolean(RemoteConfig.IS_PEER_REVIEW_ENABLED)) {
            when {
                lessonData.lesson.isTeacher && blockName in StepQuizReviewTeacherFragment.supportedQuizTypes ->
                    StepQuizReviewTeacherFragment.newInstance(stepPersistentWrapper.step.id, instructionType)

                !lessonData.lesson.isTeacher && blockName in StepQuizReviewFragment.supportedQuizTypes ->
                    StepQuizReviewFragment.newInstance(stepPersistentWrapper.step.id, instructionType)

                else ->
                    getDefaultQuizFragment(stepPersistentWrapper)
            }
        } else {
            getDefaultQuizFragment(stepPersistentWrapper)
        }
{'fraction_non_alphanumeric': 0.07588294651866802, 'fraction_numerical': 0.0008072653884964682, 'mean_word_length': 5.110974106041923, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2148952', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1447, 'n_words': 166}