# CMSControllerMock.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.cms

    import dk.nsp.api.cms.models.*
    import dk.nsp.api.configuration.models.ChecklistDTO
    import dk.nsp.api.configuration.models.ChecklistItemDTO
    import dk.nsp.api.util.extensions.asyncIO
    import dk.nsp.shared.Failed
    import dk.nsp.shared.ResultWrapper
    import dk.nsp.shared.Success
    import dk.nsp.shared.toSuccess
    import kotlinx.coroutines.CoroutineScope
    import kotlinx.coroutines.Deferred
    import java.time.LocalDateTime

    class CMSControllerMock : ICMSController {
        override fun getDictionary(scope: CoroutineScope): Deferred<ResultWrapper<List<DictionaryEntryDTO>>> =
            scope.asyncIO {
                Failed(NotImplementedError())
            }

        override fun getFAQ(scope: CoroutineScope): Deferred<ResultWrapper<List<FAQItemDTO>>> =
            scope.asyncIO {
                Failed(NotImplementedError())
            }

        val articleCategories = (1..10).mapIndexed { index, i -> createArticleCategory(index) }
        override fun getArticleSections(scope: CoroutineScope): Deferred<ResultWrapper<List<ArticleCategoryDTO>>> =
            scope.asyncIO {
                Success(articleCategories)
            }

        private fun createArticleCategory(index: Int): ArticleCategoryDTO {
            val articles = (1..10).mapIndexed { index, i -> createArticleDto(index) }
            return ArticleCategoryDTO(
                categoryId = index,
                name = "Article category name $index",
                description = "Article description $index",
                icon = "https://graviditetscms.sundhedsdata.dk/wp-content/themes/graviditet-cms/category_icons/tanker@3x.png",
                articles = articles,
                if (index.mod(2) == 0) {
                    "efterfoedsel"
                } else {
                    "Category $index"
                }
            )
        }

        private fun createArticleDto(i: Int): ArticleDTO {
            val contentSections = (1..42).mapIndexed { index, i -> createArticleContentSection(index) }
            return ArticleDTO(
                id = i,
                title = "Article title $i",
                searchOrder = i,
                lastUpdated = LocalDateTime.now().minusHours(i.toLong()),
                description = "Article description $i",
                sections = contentSections
            )
        }

        private fun createArticleContentSection(i: Int): ArticleContentSectionDTO {
            return ArticleContentSectionDTO(
                id = i,
                "Article section title $i",
                searchOrder = i,
                content = (0..i).joinToString("\n") { "Content of an article ($it) longwordhere" },
                weeks = listOf("$i")
            )
        }

        override fun getArticlesForWeek(
            scope: CoroutineScope,
            week: Int
        ): Deferred<ResultWrapper<List<ArticleCategoryDTO>>> = scope.asyncIO {
            when (week) {
                41 -> {
                    emptyList<ArticleCategoryDTO>()
                }
                42 -> {
                    listOf(
                        ArticleCategoryDTO(
                            10,
                            "CatName",
                            "CatDesc",
                            "https://graviditetscms.sundhedsdata.dk/wp-content/themes/graviditet-cms/category_icons/tanker@3x.png",
                            listOf(
                                ArticleDTO(
                                    1,
                                    "ArtTitle",
                                    1,
                                    LocalDateTime.now(),
                                    "Description for article",
                                    emptyList()
                                )
                            ),
                            "foerfoedsel"
                        ),
                        ArticleCategoryDTO(
                            10,
                            "Efterfødsel",
                            "EfterFødsel description",
                            "https://graviditetscms.sundhedsdata.dk/wp-content/themes/graviditet-cms/category_icons/tanker@3x.png",
                            listOf(
                                ArticleDTO(
                                    1,
                                    "Efterfødsels artikel",
                                    1,
                                    LocalDateTime.now(),
                                    "Description for article",
                                    emptyList()
                                )
                            ),
                            "efterfoedsel"
                        )
                    )
                }
                else -> emptyList()
            }.toSuccess()
        }

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

        override fun getChecklists(scope: CoroutineScope): Deferred<ResultWrapper<List<ChecklistDTO>>> =
            scope.asyncIO {
                val checklists = mutableListOf(
                    ChecklistDTO(
                        0,
                        "Fødetasken",
                        "Du kan starte med at købe det allermest nødvendige og så afvente, hvad du kan låne købe brugt, og hvad du evt. får i barselsgave er også en god idé at tænke på størrelsen af det, du køber. Nyfødte vokser meget hurtigt, så der skal helst ikke være for meget i str. 50. Undgå også at købe toj og overtoj med snorelukning, der kan kvæle barnet.",
                        mutableListOf(
                            ChecklistItemDTO("itemId0", "Mad og drikke", "Test description"),
                            ChecklistItemDTO("itemId1", "Kamera og oplader", null)
                        )
                    ),
                    ChecklistDTO(
                        1,
                        "Test kort",
                        null,
                        mutableListOf(
                            ChecklistItemDTO("itemId2", "1", null),
                            ChecklistItemDTO("itemId3", "2", null),
                            ChecklistItemDTO("itemId4", "3", null),
                            ChecklistItemDTO("itemId5", "4", null),
                            ChecklistItemDTO("itemId6", "5", null),
                            ChecklistItemDTO("itemId7", "6", null)
                        )
                    )
                )

                Success(checklists)
            }

        override fun getPageContent(
            scope: CoroutineScope,
            pagePath: String
        ): Deferred<ResultWrapper<PageDTO>> = scope.asyncIO {
            //Page paths defined in SettingsUrlConstants.kt
            if (pagePath == "samtykke") {
                Success(PageDTO("Her er et samtykke, accepter for at komme videre"))
            } else {
                Failed(NotImplementedError())
            }
        }
    }