package solutions.tretter.githugandroid

/**
 * Port of the upstream ruby-githug `rebase_onto` 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 rebaseOntoLevel(): Level = level(
    id = "rebase_onto",
    title = "Rebase Onto",
    description = "You have created your branch from `wrong_branch` and already made some commits, and you realise that you needed to create your branch from `master`. Rebase your commits onto `master` branch so that you don't have `wrong_branch` commits.",
    hints = listOf("You want to research the `git rebase` commands `--onto` argument"),
    commandSuggestions = listOf("git rebase --onto master wrong_branch readme-update"),
    setup = { RepoState(initialized = true, headBranch = "readme-update", branches = mapOf("master" to 1, "wrong_branch" to 2, "readme-update" to 4)) },
    validator = repoPredicate { repo -> repo.headBranch == "readme-update" && "rebase-onto" in repo.maintenanceActions },
    testCases = listOf(
        levelTestCase("rebase onto explicit branch", "git rebase --onto master wrong_branch readme-update"),
        levelTestCase("rebase onto current branch", "git rebase --onto master wrong_branch"),
    ),
)
