# BuildFlavor.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

    import dk.nsp.mingraviditet.shared.BuildConfig

    sealed class BuildFlavor {
        object ProjectEnv : BuildFlavor()
        object InternalTest : BuildFlavor()
        object Staging1 : BuildFlavor()
        object Staging2 : BuildFlavor()
        object Mock : BuildFlavor()
        object GooglePlay : BuildFlavor()

        companion object {
            /**
             * Converts the given string to a typesafe [BuildFlavor], if no match was found this will throw a [RuntimeException]
             */
            @Throws(RuntimeException::class)
            fun from(flavorString: String) = when (flavorString) {
                "projectEnv" -> ProjectEnv
                "internalTest" -> InternalTest
                "staging1" -> Staging1
                "staging2" -> Staging2
                "mock" -> Mock
                "googlePlay" -> GooglePlay
                else -> throw RuntimeException("Unknown BuildConfig.FLAVOR encountered. Ensure that you have defined this flavor in ${BuildFlavor::class.java.`package`}")
            }
        }

        val isTpaEnabled: Boolean
            get() {
                val enabledForFlavor = when (this) {
                    InternalTest,
                    ProjectEnv,
                    Staging1,
                    Staging2 -> true
                    Mock,
                    GooglePlay -> false
                }
                return !BuildConfig.DEBUG && enabledForFlavor
            }

        val isTPADistributionEnabled: Boolean
            get() {
                val enabledForFlavor = when (this) {
                    ProjectEnv,
                    InternalTest,
                    Staging1,
                    Staging2 -> true
                    Mock,
                    GooglePlay -> false
                }
                return !BuildConfig.DEBUG && enabledForFlavor
            }
    }