package solutions.tretter.githugandroid

/**
 * Port of the upstream ruby-githug `ignore` 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 ignoreLevel(): Level = level(
    id = "ignore",
    title = "Ignore",
    description = "The text editor 'vim' creates files ending in `.swp` (swap files) for all files that are currently open. We don't want them creeping into the repository. Make this repository ignore those swap files which are ending in `.swp`.",
    hints = listOf("You may have noticed there is a file named `.gitignore` in the repository."),
    commandSuggestions = listOf("echo \"*.swp\" >> .gitignore", "git status"),
    setup = { RepoState(initialized = true, files = listOf(GitFile(".gitignore", tracked = true)), branches = mapOf("master" to 0)) },
    validator = repoPredicate { repo -> repo.files.find { it.name == ".gitignore" }?.content?.lineSequence()?.any { line -> line.trim() == "*.swp" } == true },
    testCases = listOf(
        levelTestCase("append quoted pattern", "echo \"*.swp\" >> .gitignore"),
        levelTestCase("compact redirect", "echo '*.swp'>.gitignore"),
    ),
)
