package solutions.tretter.githugandroid

/**
 * Port of the upstream ruby-githug `status` 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 statusLevel(): Level = level(
    id = "status",
    title = "Status",
    description = "Among the files in this repository, which of them is untracked?",
    hints = listOf("You are looking for a command to identify the status of the repository."),
    commandSuggestions = listOf("git status"),
    setup = {
        RepoState(
            initialized = true,
            files = listOf(
                GitFile("config.rb", staged = true),
                GitFile("README", staged = true),
                GitFile("setup.rb", staged = true),
                GitFile("deploy.rb", staged = true),
                GitFile("Guardfile", staged = true),
                GitFile("database.yml"),
            ),
            branches = mapOf("master" to 0),
        )
    },
    nativeSetup = {
        resetFiles()
        listOf("config.rb", "README", "setup.rb", "deploy.rb", "Guardfile").forEach { file ->
            write(file)
            git("add", file)
        }
        write("database.yml")
        true
    },
    validator = commandAnswer("database.yml"),
    testCases = listOf(
        levelTestCase("answer untracked file", "database.yml"),
    ),
    setupChecks = listOf(
        levelSetupCheck(
            "database.yml is the only untracked file",
            "status should start with database.yml as the only untracked file.",
        ) { repo ->
            repo.files.filter { !it.staged && !it.tracked && !it.deleted }.map { it.name } == listOf("database.yml")
        },
    ),
)
