package solutions.tretter.githugandroid

/**
 * Port of the upstream ruby-githug `delete_branch` 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 deleteBranchLevel(): Level = level(
    id = "delete_branch",
    title = "Delete Branch",
    description = "You have created too many branches for your project. There is an old branch in your repo called 'delete_me', you should delete it.",
    hints = listOf("Running 'git --help branch' will give you a list of branch commands."),
    commandSuggestions = listOf("git branch -d delete_me"),
    setup = {
        RepoState(
            initialized = true,
            files = listOf(GitFile("readme", tracked = true)),
            commits = listOf(CommitNode("0000001", "first commit")),
            branches = mapOf("master" to 1, "delete_me" to 1),
        )
    },
    nativeSetup = {
        resetFiles()
        write("readme")
        addCommit("first commit", "readme")
        git("branch", "delete_me")
        true
    },
    validator = repoPredicate { repo -> "delete_me" !in repo.branches },
    testCases = listOf(
        levelTestCase("delete branch", "git branch -d delete_me"),
        levelTestCase("force delete branch", "git branch -D delete_me"),
    ),
    setupChecks = listOf(
        levelSetupCheck(
            "upstream readme and delete branch are present",
            "delete_branch should start with tracked readme and delete_me branch.",
        ) { repo ->
            repo.files.any { it.name == "readme" && it.tracked } &&
                repo.branches.containsKey("delete_me")
        },
    ),
)
