package solutions.tretter.githugandroid

import java.io.File

/**
 * Port of the upstream ruby-githug `push_tags` 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 pushTagsLevel(): Level = level(
    id = "push_tags",
    title = "Push Tags",
    description = "A tag in the local repository isn't pushed into remote repository. Push it now.",
    hints = listOf("Take a look at `--tags` flag of `git push`"),
    commandSuggestions = listOf("git push --tags"),
    setup = { RepoState(initialized = true, tags = listOf("tag_to_be_pushed"), branches = mapOf("master" to 2), remotes = mapOf("origin" to "remote")) },
    nativeSetup = {
        resetFiles()
        write("file1")
        addCommit("First commit", "file1")
        tag("tag_to_be_pushed")
        write("file2")
        addCommit("Second commit", "file2")
        val remote = siblingRepo("origin")
        git("remote", "add", "push-tags-setup-origin", File(remote, ".git").absolutePath)
        git("push", "push-tags-setup-origin", "master")
        git("remote", "remove", "push-tags-setup-origin")
        git(remote, "checkout", "-f", "master")
        git("remote", "add", "origin", File(remote, ".git").absolutePath)
        true
    },
    validator = repoPredicate { repo -> "tag_to_be_pushed" in repo.pushedTags },
    testCases = listOf(
        levelTestCase("push all tags", "git push --tags"),
        levelTestCase("push tags to origin", "git push origin --tags"),
    ),
)
