package solutions.tretter.githugandroid

/**
 * Port of the upstream ruby-githug `revert` 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 revertLevel(): Level = level(
    id = "revert",
    title = "Revert",
    description = "You have committed several times but want to undo the middle commit. All commits have been pushed, so you can't change existing history.",
    hints = listOf("Try the revert command."),
    commandSuggestions = listOf("git revert HEAD~1"),
    setup = { RepoState(initialized = true, commits = listOf(CommitNode("1", "First commit"), CommitNode("2", "Bad commit"), CommitNode("3", "Second commit")), branches = mapOf("master" to 3), pushedBranches = setOf("origin/master")) },
    nativeSetup = {
        resetFiles()
        write("file1")
        addCommit("First commit", "file1")
        write("file3")
        addCommit("Bad commit", "file3")
        write("file2")
        addCommit("Second commit", "file2")
        true
    },
    validator = repoPredicate { repo -> repo.commits.any { it.message.startsWith("Revert") } },
    testCases = listOf(
        levelTestCase("revert middle commit", "git revert HEAD~1"),
    ),
)
