# MockCMSDataSource.kt

    /*
     * The MIT License
     *
     * Original work sponsored and donated by The Danish Health Data Authority (http://www.sundhedsdatastyrelsen.dk)
     *
     * Copyright (C) 2023 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.mingraviditet.core.network.cms.mock

    import dk.nsp.mingraviditet.core.network.cms.CMSDataSource
    import dk.nsp.mingraviditet.core.network.cms.models.NetworkArticle
    import dk.nsp.mingraviditet.core.network.cms.models.NetworkArticleCategory
    import dk.nsp.mingraviditet.core.network.cms.models.NetworkArticleSection
    import dk.nsp.mingraviditet.core.network.cms.models.NetworkChecklist
    import dk.nsp.mingraviditet.core.network.cms.models.NetworkChecklistItem
    import dk.nsp.mingraviditet.core.network.cms.models.NetworkFAQItem
    import dk.nsp.mingraviditet.core.network.cms.models.NetworkPage
    import dk.nsp.mingraviditet.core.network.cms.models.NetworkRecommendedArticles
    import dk.nsp.mingraviditet.core.network.cms.models.NetworkRedirectArticle
    import dk.nsp.mingraviditet.core.network.cms.models.NetworkSearchResult
    import dk.nsp.mingraviditet.core.shared.network.Failed
    import dk.nsp.mingraviditet.core.shared.network.ResultWrapper
    import dk.nsp.mingraviditet.core.shared.network.Success
    import dk.nsp.mingraviditet.core.shared.network.toSuccess
    import java.time.LocalDateTime
    import javax.inject.Inject

    class MockCMSDataSource @Inject constructor() : CMSDataSource {
        private val articleCategories = (1..10).map { createArticleCategory(it) }

        override suspend fun getFAQ(): ResultWrapper<List<NetworkFAQItem>> {
            return listOf(
                NetworkFAQItem(
                    "faqTitle",
                    "FAQText",
                    LocalDateTime.of(2020, 8, 7, 6, 5),
                ),
            ).toSuccess()
        }

        override suspend fun getArticleSections(): ResultWrapper<List<NetworkArticleCategory>> {
            return Success(articleCategories)
        }

        override suspend fun getAfterBirthArticleCategories(afterBirthWeek: Int): ResultWrapper<NetworkRecommendedArticles> {
            return when (afterBirthWeek) {
                2 -> NetworkRecommendedArticles(currentWeek = emptyList(), nextWeek = emptyList())
                else -> NetworkRecommendedArticles(
                    currentWeek = listOf(getAfterBirthCategory(afterBirthWeek)),
                    nextWeek = emptyList(),
                )
            }.toSuccess()
        }

        override suspend fun getArticleCategories(week: Int): ResultWrapper<NetworkRecommendedArticles> {
            return when (week) {
                37 -> NetworkRecommendedArticles(
                    currentWeek = listOf(
                        getArticleCategory(week),
                        getArticleCategory(week),
                    ),
                    nextWeek = emptyList(),
                )

                42 -> {
                    NetworkRecommendedArticles(
                        currentWeek = listOf(
                            getArticleCategory(week),
                            getArticleCategory(week),
                        ),
                        nextWeek = emptyList(),
                    )
                }

                else -> NetworkRecommendedArticles(currentWeek = emptyList(), nextWeek = emptyList())
            }.toSuccess()
        }

        override suspend fun searchArticles(query: String): ResultWrapper<List<NetworkSearchResult>> {
            return Failed(NotImplementedError())
        }

        override suspend fun getChecklists(): ResultWrapper<List<NetworkChecklist>> {
            val checklists = mutableListOf(
                NetworkChecklist(
                    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(
                        NetworkChecklistItem("itemId0", "Mad og drikke"),
                        NetworkChecklistItem("itemId1", "Kamera og oplader"),
                    ),
                ),
                NetworkChecklist(
                    1,
                    "Test kort",
                    null,
                    mutableListOf(
                        NetworkChecklistItem("itemId2", "1"),
                        NetworkChecklistItem("itemId3", "2"),
                        NetworkChecklistItem("itemId4", "3"),
                        NetworkChecklistItem("itemId5", "4"),
                        NetworkChecklistItem("itemId6", "5"),
                        NetworkChecklistItem("itemId7", "6"),
                    ),
                ),
            )
            return Success(checklists)
        }

        override suspend fun getPageContent(pagePath: String): ResultWrapper<NetworkPage> {
            return if (pagePath == "lille-samtykke-app-aaben") {
                Success(NetworkPage("Her er et samtykke, accepter for at komme videre"))
            } else {
                Failed(NotImplementedError())
            }
        }

        private fun createArticleCategory(index: Int): NetworkArticleCategory {
            val articles = (1..10).map { createArticleDto(it) }
            return NetworkArticleCategory(
                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.rem(2) == 0) {
                    "efterfoedsel"
                } else {
                    "Category $index"
                },
            )
        }

        private fun createArticleDto(i: Int): NetworkArticle {
            val contentSections = (1..42).map { createArticleContentSection(it) }
            return NetworkArticle(
                id = i + 1790,
                title = "Article title $i",
                searchOrder = i,
                lastUpdated = LocalDateTime.now().minusHours(i.toLong()),
                description = "Article description $i",
                content = "Article content $i",
                sections = contentSections,
            )
        }

        private fun createArticleContentSection(i: Int): NetworkArticleSection {
            return NetworkArticleSection(
                id = i,
                "Article section title $i",
                searchOrder = i,
                content = (0..i).joinToString("\n") { "Content of an article ($it) longwordhere <a href=\"https://graviditetscms.sundhedsdata.dk/det-goer-ondt/\">Link her</a>" },
                weeks = listOf("$i"),
            )
        }

        private fun getAfterBirthCategory(afterBirthWeek: Int) = NetworkArticleCategory(
            afterBirthWeek,
            name = "Efterfødsel - uge $afterBirthWeek",
            description = "Dette er en mock artikel for uge $afterBirthWeek efter fødsel",
            icon = "https://graviditetscms.sundhedsdata.dk/wp-content/themes/graviditet-cms/category_icons/tanker@3x.png",
            listOf(
                NetworkArticle(
                    1,
                    "ArtTitle uge $afterBirthWeek",
                    1,
                    LocalDateTime.now(),
                    "Description for article",
                    "content for article",
                    emptyList(),
                ),
            ),
            "sluggy",
        )

        private fun getArticleCategory(pregnancyWeek: Int) = NetworkArticleCategory(
            10,
            "CatName - uge $pregnancyWeek",
            "CatDesc",
            "https://graviditetscms.sundhedsdata.dk/wp-content/themes/graviditet-cms/category_icons/tanker@3x.png",
            listOf(
                NetworkArticle(
                    1,
                    "ArtTitle uge $pregnancyWeek",
                    1,
                    LocalDateTime.now(),
                    "Description for article",
                    "Content for article",
                    emptyList(),
                ),
            ),
            "sluggy",
        )

        override suspend fun getRedirectLink(url: String): String {
            TODO("Not yet implemented")
        }

        override suspend fun getRedirectArticle(id: Int): ResultWrapper<NetworkRedirectArticle> {
            TODO("Not yet implemented")
        }
    }