package solutions.tretter.githugandroid

/**
 * Port of the upstream ruby-githug `include` 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 includeLevel(): Level = level(
    id = "include",
    title = "Include",
    description = "Notice a few files with the '.a' extension. We want git to ignore all the files except the 'lib.a' file.",
    hints = listOf("Using `git help ignore`, read about the optional prefix to negate a pattern."),
    commandSuggestions = listOf("echo \"*.a\" >> .gitignore", "echo \"!lib.a\" >> .gitignore"),
    setup = { RepoState(initialized = true, files = listOf(GitFile(".gitignore", tracked = true), GitFile("lib.a"), GitFile("main.a")), branches = mapOf("master" to 0)) },
    validator = repoPredicate { repo -> repo.files.find { it.name == ".gitignore" }?.content?.lineSequence()?.map { it.trim() }?.toSet()?.let { "*.a" in it && "!lib.a" in it } == true },
    testCases = listOf(
        levelTestCase("append both patterns", "echo \"*.a\" >> .gitignore", "echo \"!lib.a\" >> .gitignore"),
        levelTestCase("overwrite both patterns", "echo \"*.a\" > .gitignore", "echo \"!lib.a\" >> .gitignore"),
    ),
)
