package solutions.tretter.githugandroid

/**
 * Port of the upstream ruby-githug `checkout_tag_over_branch` level.
 *
 * Setup documents the repository shape the learner explores. Evaluation is kept
 * state-based whenever the exercise changes repository objects; answer-only
 * levels intentionally validate the answer entered at the prompt.
 */
internal fun checkoutTagOverBranchLevel(): Level = level(
    id = "checkout_tag_over_branch",
    title = "Checkout Tag Over Branch",
    description = "You need to fix a bug in the version 1.2 of your app. Checkout the tag `v1.2` (Note: There is also a branch named `v1.2`).",
    hints = listOf("You should think about specifying you're after the tag named `v1.2` (think `tags/`)."),
    commandSuggestions = listOf("git checkout tags/v1.2"),
    setup = { RepoState(initialized = true, tags = listOf("v1.0", "v1.2", "v1.5"), branches = mapOf("master" to 5, "v1.2" to 6)) },
    nativeSetup = {
        checkoutTagHistory()
        checkoutNew("v1.2")
        write("file3", "some feature\n")
        addCommit("Developing new features", "file3")
        checkout("master")
        true
    },
    validator = repoPredicate { repo -> repo.headBranch == "tags/v1.2" || repo.branches.keys.any { "detached at v1.2" in it } },
    testCases = listOf(
        levelTestCase("checkout tag namespace", "git checkout tags/v1.2"),
        levelTestCase("checkout refs tag", "git checkout refs/tags/v1.2"),
    ),
)
