# ConfigurationControllerMock.kt

    /*
     * The MIT License
     *
     * Original work sponsored and donated by The Danish Health Data Authority (http://www.sundhedsdatastyrelsen.dk)
     *
     * Copyright (C) 2021 The Danish Health Data Authority (http://www.sundhedsdatastyrelsen.dk)
     *
     *
     * Permission is hereby granted, free of charge, to any person obtaining a copy of
     * this software and associated documentation files (the "Software"), to deal in
     * the Software without restriction, including without limitation the rights to
     * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
     * of the Software, and to permit persons to whom the Software is furnished to do
     * so, subject to the following conditions:
     *
     *
     * The above copyright notice and this permission notice shall be included in all
     * copies or substantial portions of the Software.
     *
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     * SOFTWARE.
     */

    package dk.nsp.api.configuration

    import dk.nsp.api.util.extensions.asyncIO
    import dk.nsp.models.CheckListItem
    import dk.nsp.models.DateOfBirth
    import dk.nsp.shared.Failed
    import dk.nsp.shared.ResultWrapper
    import dk.nsp.shared.Success
    import kotlinx.coroutines.CoroutineScope
    import kotlinx.coroutines.Deferred
    import kotlinx.coroutines.delay
    import java.time.LocalDateTime

    class ConfigurationControllerMock : IConfigurationController {

        override fun updateChecklistItem(
            scope: CoroutineScope,
            episodeOfCareId: String,
            checklistId: String,
            updateChecklistBody: CheckListItem
        ): Deferred<ResultWrapper<CheckListItem>> = scope.asyncIO {
            delay(150)

    //        val matchingChecklist = checklists.firstOrNull { it.id == checklist.id }
    //
    //        if (matchingChecklist != null) {
    //            val foundItem = matchingChecklist.items.firstOrNull { it.id == checklistItem.id }
    //
    //            if (foundItem != null) {
    //                val indexOfItem = matchingChecklist.items.indexOf(foundItem)
    //                val toggledItem = foundItem.copy(value = !foundItem.value)
    //
    //                val copyOfList = matchingChecklist.items.toMutableList()
    //
    //                copyOfList.removeAt(indexOfItem)
    //                copyOfList.add(indexOfItem, toggledItem)
    //
    //                val newChecklist = checklist.copy(items = copyOfList)
    //
    //                val indexOfChecklist = checklists.indexOfFirst { it.id == checklist.id }
    //                checklists[indexOfChecklist] = newChecklist
    //
    //                Success(toggledItem)
    //            } else {
            Failed(Exception("Kunne ikke finde checklisten"))
    //            }
    //
    //        } else {
    //            Failed(Resources.NotFoundException("Could not find checklist"))
    //        }
        }

        override fun getCheckedChecklistItems(
            scope: CoroutineScope,
            episodeOfCareId: String
        ): Deferred<ResultWrapper<List<String>>> =
            scope.asyncIO {
                Failed(NotImplementedError())
            }

        private var mockDateOfBirth: DateOfBirth = DateOfBirth(
            LocalDateTime.now().minusWeeks(1)
        )

        override fun getDateOfBirth(
            scope: CoroutineScope,
            episodeOfCareId: String
        ): Deferred<ResultWrapper<DateOfBirth>> = scope.asyncIO {
            Success(mockDateOfBirth)
        }

        override fun updateDateOfBirth(
            scope: CoroutineScope,
            episodeOfCareId: String,
            newDate: LocalDateTime?
        ): Deferred<ResultWrapper<DateOfBirth>> = scope.asyncIO {
            val dateOfBirth = DateOfBirth(newDate)
            mockDateOfBirth = dateOfBirth
            Success(dateOfBirth)
        }

        override fun removeConsent(scope: CoroutineScope): Deferred<ResultWrapper<Unit>> =
            scope.asyncIO {
                Failed(Exception("Kan ikke slette consent i mock"))
            }
    }