package solutions.tretter.githugandroid

/**
 * Port of the upstream ruby-githug `restore` 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 restoreLevel(): Level = level(
    id = "restore",
    title = "Restore",
    description = "You decided to delete your latest commit by running `git reset --hard HEAD^` (not a smart thing to do). Now you changed your mind and want that commit back. Restore the deleted commit.",
    hints = listOf("The commit is still floating around somewhere. Have you checked out `git reflog`?"),
    commandSuggestions = listOf("git checkout HEAD@{1} -- file3"),
    setup = { RepoState(initialized = true, files = listOf(GitFile("file1", tracked = true), GitFile("file2", tracked = true)), commits = listOf(CommitNode("1", "Initial commit"), CommitNode("2", "First commit")), branches = mapOf("master" to 2)) },
    nativeSetup = {
        resetFiles()
        write("file1")
        addCommit("Initial commit", "file1")
        write("file2")
        addCommit("First commit", "file2")
        write("file3")
        addCommit("Restore this commit", "file3")
        git("reset", "--hard", "HEAD^")
        true
    },
    validator = repoPredicate { repo -> repo.files.any { it.name == "file3" && it.tracked } },
    testCases = listOf(
        levelTestCase("checkout file from reflog commit", "git checkout HEAD@{1} -- file3"),
    ),
)
