|
| 1 | +package com.threegap.bitnagil.domain.routine.usecase |
| 2 | + |
| 3 | +import com.threegap.bitnagil.domain.routine.model.RoutineCompletionInfo |
| 4 | +import com.threegap.bitnagil.domain.routine.model.ToggleStrategy |
| 5 | +import com.threegap.bitnagil.domain.routine.repository.RoutineRepository |
| 6 | +import javax.inject.Inject |
| 7 | + |
| 8 | +class ApplyRoutineToggleUseCase @Inject constructor( |
| 9 | + private val routineRepository: RoutineRepository, |
| 10 | + private val toggleRoutineUseCase: ToggleRoutineUseCase, |
| 11 | +) { |
| 12 | + suspend operator fun invoke( |
| 13 | + dateKey: String, |
| 14 | + routineId: String, |
| 15 | + isCompleted: Boolean, |
| 16 | + subRoutineCompletionStates: List<Boolean>, |
| 17 | + strategy: ToggleStrategy, |
| 18 | + ) { |
| 19 | + val toggledState = |
| 20 | + when (strategy) { |
| 21 | + is ToggleStrategy.Main -> { |
| 22 | + toggleRoutineUseCase.toggleMainRoutine( |
| 23 | + isCompleted = isCompleted, |
| 24 | + subRoutineStates = subRoutineCompletionStates, |
| 25 | + ) |
| 26 | + } |
| 27 | + |
| 28 | + is ToggleStrategy.Sub -> { |
| 29 | + toggleRoutineUseCase.toggleSubRoutine( |
| 30 | + index = strategy.index, |
| 31 | + subRoutineStates = subRoutineCompletionStates, |
| 32 | + ) ?: return |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + val completionInfo = RoutineCompletionInfo( |
| 37 | + routineId = routineId, |
| 38 | + routineCompleteYn = toggledState.isCompleted, |
| 39 | + subRoutineCompleteYn = toggledState.subRoutinesIsCompleted, |
| 40 | + ) |
| 41 | + |
| 42 | + routineRepository.applyRoutineToggle(dateKey, routineId, completionInfo) |
| 43 | + } |
| 44 | +} |
0 commit comments