// Code generated by cmd/genactions; DO NOT EDIT.
package actionmeta

import (
	"fmt"
	"sort"
	"strings"
)

var builtInActionScopes = map[string][]string{
	"bookmarks.apply":                            {"bookmarks"},
	"bookmarks.bookmark_delete":                  {"bookmarks"},
	"bookmarks.bookmark_forget":                  {"bookmarks"},
	"bookmarks.bookmark_move":                    {"bookmarks"},
	"bookmarks.bookmark_track":                   {"bookmarks"},
	"bookmarks.bookmark_untrack":                 {"bookmarks"},
	"bookmarks.cancel":                           {"bookmarks"},
	"bookmarks.cycle_remotes":                    {"bookmarks"},
	"bookmarks.cycle_remotes_back":               {"bookmarks"},
	"bookmarks.filter":                           {"bookmarks"},
	"bookmarks.move_down":                        {"bookmarks"},
	"bookmarks.move_up":                          {"bookmarks"},
	"bookmarks.page_down":                        {"bookmarks"},
	"bookmarks.page_up":                          {"bookmarks"},
	"bookmarks.quit":                             {"bookmarks"},
	"choose.apply":                               {"choose"},
	"choose.cancel":                              {"choose"},
	"choose.move_down":                           {"choose"},
	"choose.move_up":                             {"choose"},
	"command_history.close":                      {"command_history"},
	"command_history.delete_selected":            {"command_history"},
	"command_history.move_down":                  {"command_history"},
	"command_history.move_up":                    {"command_history"},
	"diff.half_page_down":                        {"diff"},
	"diff.half_page_up":                          {"diff"},
	"diff.left":                                  {"diff"},
	"diff.move_bottom":                           {"diff"},
	"diff.move_top":                              {"diff"},
	"diff.page_down":                             {"diff"},
	"diff.page_up":                               {"diff"},
	"diff.right":                                 {"diff"},
	"diff.scroll_down":                           {"diff"},
	"diff.scroll_up":                             {"diff"},
	"diff.show":                                  {"diff"},
	"diff.toggle_wrap":                           {"diff"},
	"file_search.apply":                          {"file_search"},
	"file_search.cancel":                         {"file_search"},
	"file_search.edit":                           {"file_search"},
	"file_search.move_down":                      {"file_search"},
	"file_search.move_up":                        {"file_search"},
	"file_search.page_down":                      {"file_search"},
	"file_search.page_up":                        {"file_search"},
	"file_search.preview_half_page_down":         {"file_search"},
	"file_search.preview_half_page_up":           {"file_search"},
	"file_search.toggle":                         {"file_search"},
	"git.apply":                                  {"git"},
	"git.cancel":                                 {"git"},
	"git.cycle_remotes":                          {"git"},
	"git.cycle_remotes_back":                     {"git"},
	"git.fetch":                                  {"git"},
	"git.filter":                                 {"git"},
	"git.move_down":                              {"git"},
	"git.move_up":                                {"git"},
	"git.page_down":                              {"git"},
	"git.page_up":                                {"git"},
	"git.push":                                   {"git"},
	"git.quit":                                   {"git"},
	"help.apply":                                 {"help"},
	"help.cancel":                                {"help"},
	"help.close":                                 {"help"},
	"help.filter":                                {"help"},
	"help.move_bottom":                           {"help"},
	"help.move_top":                              {"help"},
	"help.page_down":                             {"help"},
	"help.page_up":                               {"help"},
	"help.scroll_down":                           {"help"},
	"help.scroll_up":                             {"help"},
	"input.apply":                                {"input"},
	"input.cancel":                               {"input"},
	"oplog.close":                                {"oplog"},
	"oplog.diff":                                 {"oplog"},
	"oplog.move_down":                            {"oplog"},
	"oplog.move_up":                              {"oplog"},
	"oplog.page_down":                            {"oplog"},
	"oplog.page_up":                              {"oplog"},
	"oplog.quick_search.clear":                   {"oplog.quick_search"},
	"oplog.quick_search.next":                    {"oplog.quick_search"},
	"oplog.quick_search.prev":                    {"oplog.quick_search"},
	"oplog.quit":                                 {"oplog"},
	"oplog.restore":                              {"oplog"},
	"oplog.revert":                               {"oplog"},
	"password.apply":                             {"password"},
	"password.cancel":                            {"password"},
	"redo.apply":                                 {"redo"},
	"redo.cancel":                                {"redo"},
	"redo.next":                                  {"redo"},
	"redo.prev":                                  {"redo"},
	"revisions.abandon.ace_jump":                 {"revisions.abandon"},
	"revisions.abandon.apply":                    {"revisions.abandon"},
	"revisions.abandon.cancel":                   {"revisions.abandon"},
	"revisions.abandon.force_apply":              {"revisions.abandon"},
	"revisions.abandon.jump_to_working_copy":     {"revisions.abandon"},
	"revisions.abandon.select_descendants":       {"revisions.abandon"},
	"revisions.abandon.toggle_select":            {"revisions.abandon"},
	"revisions.absorb.ace_jump":                  {"revisions.absorb"},
	"revisions.absorb.apply":                     {"revisions.absorb"},
	"revisions.absorb.cancel":                    {"revisions.absorb"},
	"revisions.absorb.jump_to_working_copy":      {"revisions.absorb"},
	"revisions.absorb.select_descendants":        {"revisions.absorb"},
	"revisions.absorb.toggle_select":             {"revisions.absorb"},
	"revisions.ace_jump":                         {"revisions"},
	"revisions.ace_jump.apply":                   {"revisions.ace_jump"},
	"revisions.ace_jump.cancel":                  {"revisions.ace_jump"},
	"revisions.apply":                            {"revisions"},
	"revisions.cancel":                           {"revisions"},
	"revisions.commit":                           {"revisions"},
	"revisions.describe":                         {"revisions"},
	"revisions.details.absorb":                   {"revisions.details"},
	"revisions.details.cancel":                   {"revisions.details"},
	"revisions.details.confirmation.apply":       {"revisions.details.confirmation"},
	"revisions.details.confirmation.cancel":      {"revisions.details.confirmation"},
	"revisions.details.confirmation.force_apply": {"revisions.details.confirmation"},
	"revisions.details.confirmation.next":        {"revisions.details.confirmation"},
	"revisions.details.confirmation.prev":        {"revisions.details.confirmation"},
	"revisions.details.diff":                     {"revisions.details"},
	"revisions.details.move_down":                {"revisions.details"},
	"revisions.details.move_up":                  {"revisions.details"},
	"revisions.details.page_down":                {"revisions.details"},
	"revisions.details.page_up":                  {"revisions.details"},
	"revisions.details.quit":                     {"revisions.details"},
	"revisions.details.refresh":                  {"revisions.details"},
	"revisions.details.restore":                  {"revisions.details"},
	"revisions.details.revisions_changing_file":  {"revisions.details"},
	"revisions.details.select_file":              {"revisions.details"},
	"revisions.details.split":                    {"revisions.details"},
	"revisions.details.split_parallel":           {"revisions.details"},
	"revisions.details.squash":                   {"revisions.details"},
	"revisions.details.toggle_select":            {"revisions.details"},
	"revisions.diff":                             {"revisions"},
	"revisions.diff_edit":                        {"revisions"},
	"revisions.diff_range.apply":                 {"revisions.diff_range"},
	"revisions.diff_range.cancel":                {"revisions.diff_range"},
	"revisions.diff_range.swap":                  {"revisions.diff_range"},
	"revisions.diff_range.target_picker":         {"revisions.diff_range"},
	"revisions.duplicate.ace_jump":               {"revisions.duplicate"},
	"revisions.duplicate.apply":                  {"revisions.duplicate"},
	"revisions.duplicate.cancel":                 {"revisions.duplicate"},
	"revisions.duplicate.force_apply":            {"revisions.duplicate"},
	"revisions.duplicate.jump_to_working_copy":   {"revisions.duplicate"},
	"revisions.duplicate.set_target":             {"revisions.duplicate"},
	"revisions.duplicate.target_picker":          {"revisions.duplicate"},
	"revisions.edit":                             {"revisions"},
	"revisions.evolog.apply":                     {"revisions.evolog"},
	"revisions.evolog.cancel":                    {"revisions.evolog"},
	"revisions.evolog.diff":                      {"revisions.evolog"},
	"revisions.evolog.move_down":                 {"revisions.evolog"},
	"revisions.evolog.move_up":                   {"revisions.evolog"},
	"revisions.evolog.page_down":                 {"revisions.evolog"},
	"revisions.evolog.page_up":                   {"revisions.evolog"},
	"revisions.evolog.quit":                      {"revisions.evolog"},
	"revisions.evolog.restore":                   {"revisions.evolog"},
	"revisions.force_apply":                      {"revisions"},
	"revisions.force_edit":                       {"revisions"},
	"revisions.inline_describe.accept":           {"revisions.inline_describe"},
	"revisions.inline_describe.cancel":           {"revisions.inline_describe"},
	"revisions.inline_describe.editor":           {"revisions.inline_describe"},
	"revisions.inline_describe.force_accept":     {"revisions.inline_describe"},
	"revisions.inline_describe.new_line":         {"revisions.inline_describe"},
	"revisions.jump_to_children":                 {"revisions"},
	"revisions.jump_to_parent":                   {"revisions"},
	"revisions.jump_to_working_copy":             {"revisions"},
	"revisions.move_down":                        {"revisions"},
	"revisions.move_up":                          {"revisions"},
	"revisions.new":                              {"revisions"},
	"revisions.new_between.apply":                {"revisions.new_between"},
	"revisions.new_between.cancel":               {"revisions.new_between"},
	"revisions.new_between.toggle_insert_before": {"revisions.new_between"},
	"revisions.open_abandon":                     {"revisions"},
	"revisions.open_absorb":                      {"revisions"},
	"revisions.open_details":                     {"revisions"},
	"revisions.open_diff_range":                  {"revisions"},
	"revisions.open_duplicate":                   {"revisions"},
	"revisions.open_evolog":                      {"revisions"},
	"revisions.open_inline_describe":             {"revisions"},
	"revisions.open_new_between":                 {"revisions"},
	"revisions.open_rebase":                      {"revisions"},
	"revisions.open_revert":                      {"revisions"},
	"revisions.open_set_bookmark":                {"revisions"},
	"revisions.open_set_parents":                 {"revisions"},
	"revisions.open_squash":                      {"revisions"},
	"revisions.page_down":                        {"revisions"},
	"revisions.page_up":                          {"revisions"},
	"revisions.quick_search.clear":               {"revisions.quick_search"},
	"revisions.quick_search.input.apply":         {"revisions.quick_search.input"},
	"revisions.quick_search.input.cancel":        {"revisions.quick_search.input"},
	"revisions.quick_search.next":                {"revisions.quick_search"},
	"revisions.quick_search.prev":                {"revisions.quick_search"},
	"revisions.rebase.ace_jump":                  {"revisions.rebase"},
	"revisions.rebase.apply":                     {"revisions.rebase"},
	"revisions.rebase.cancel":                    {"revisions.rebase"},
	"revisions.rebase.force_apply":               {"revisions.rebase"},
	"revisions.rebase.jump_to_working_copy":      {"revisions.rebase"},
	"revisions.rebase.set_source":                {"revisions.rebase"},
	"revisions.rebase.set_target":                {"revisions.rebase"},
	"revisions.rebase.skip_emptied":              {"revisions.rebase"},
	"revisions.rebase.target_picker":             {"revisions.rebase"},
	"revisions.refresh":                          {"revisions"},
	"revisions.revert.apply":                     {"revisions.revert"},
	"revisions.revert.cancel":                    {"revisions.revert"},
	"revisions.revert.force_apply":               {"revisions.revert"},
	"revisions.revert.set_target":                {"revisions.revert"},
	"revisions.revert.target_picker":             {"revisions.revert"},
	"revisions.set_bookmark.apply":               {"revisions.set_bookmark"},
	"revisions.set_bookmark.autocomplete":        {"revisions.set_bookmark"},
	"revisions.set_bookmark.autocomplete_back":   {"revisions.set_bookmark"},
	"revisions.set_bookmark.cancel":              {"revisions.set_bookmark"},
	"revisions.set_parents.ace_jump":             {"revisions.set_parents"},
	"revisions.set_parents.apply":                {"revisions.set_parents"},
	"revisions.set_parents.cancel":               {"revisions.set_parents"},
	"revisions.set_parents.jump_to_working_copy": {"revisions.set_parents"},
	"revisions.set_parents.toggle_select":        {"revisions.set_parents"},
	"revisions.split":                            {"revisions"},
	"revisions.split_parallel":                   {"revisions"},
	"revisions.squash.ace_jump":                  {"revisions.squash"},
	"revisions.squash.apply":                     {"revisions.squash"},
	"revisions.squash.cancel":                    {"revisions.squash"},
	"revisions.squash.force_apply":               {"revisions.squash"},
	"revisions.squash.interactive":               {"revisions.squash"},
	"revisions.squash.jump_to_working_copy":      {"revisions.squash"},
	"revisions.squash.keep_emptied":              {"revisions.squash"},
	"revisions.squash.target_picker":             {"revisions.squash"},
	"revisions.squash.use_destination_msg":       {"revisions.squash"},
	"revisions.target_picker.apply":              {"revisions.target_picker"},
	"revisions.target_picker.autocomplete":       {"revisions.target_picker"},
	"revisions.target_picker.autocomplete_back":  {"revisions.target_picker"},
	"revisions.target_picker.cancel":             {"revisions.target_picker"},
	"revisions.target_picker.force_apply":        {"revisions.target_picker"},
	"revisions.target_picker.move_down":          {"revisions.target_picker"},
	"revisions.target_picker.move_up":            {"revisions.target_picker"},
	"revisions.toggle_select":                    {"revisions"},
	"revset.apply":                               {"revset"},
	"revset.autocomplete":                        {"revset"},
	"revset.autocomplete_back":                   {"revset"},
	"revset.cancel":                              {"revset"},
	"revset.edit":                                {"revset"},
	"revset.move_down":                           {"revset"},
	"revset.move_up":                             {"revset"},
	"revset.reset":                               {"revset"},
	"revset.set":                                 {"revset"},
	"status.input.apply":                         {"status.input"},
	"status.input.autocomplete":                  {"status.input"},
	"status.input.cancel":                        {"status.input"},
	"status.input.move_down":                     {"status.input"},
	"status.input.move_up":                       {"status.input"},
	"status.input.page_down":                     {"status.input"},
	"status.input.page_up":                       {"status.input"},
	"ui.cancel":                                  {"ui"},
	"ui.change_theme":                            {"ui"},
	"ui.exec_jj":                                 {"ui"},
	"ui.exec_shell":                              {"ui"},
	"ui.expand_status":                           {"ui"},
	"ui.file_search_toggle":                      {"ui"},
	"ui.open_bookmarks":                          {"ui"},
	"ui.open_command_history":                    {"ui"},
	"ui.open_git":                                {"ui"},
	"ui.open_help":                               {"ui"},
	"ui.open_oplog":                              {"ui"},
	"ui.open_redo":                               {"ui"},
	"ui.open_revset":                             {"ui"},
	"ui.open_undo":                               {"ui"},
	"ui.preview.show":                            {"ui.preview"},
	"ui.preview_expand":                          {"ui"},
	"ui.preview_half_page_down":                  {"ui"},
	"ui.preview_half_page_up":                    {"ui"},
	"ui.preview_scroll_down":                     {"ui"},
	"ui.preview_scroll_up":                       {"ui"},
	"ui.preview_shrink":                          {"ui"},
	"ui.preview_toggle":                          {"ui"},
	"ui.preview_toggle_bottom":                   {"ui"},
	"ui.quick_search":                            {"ui"},
	"ui.quit":                                    {"ui"},
	"ui.suspend":                                 {"ui"},
	"undo.apply":                                 {"undo"},
	"undo.cancel":                                {"undo"},
	"undo.next":                                  {"undo"},
	"undo.prev":                                  {"undo"},
}

var builtInActionArgSchemas = map[string]map[string]string{
	"diff.show": {
		"content": "string",
	},
	"revisions.abandon.apply": {
		"force": "bool",
	},
	"revisions.apply": {
		"force": "bool",
	},
	"revisions.details.confirmation.apply": {
		"force": "bool",
	},
	"revisions.details.select_file": {
		"file": "string",
	},
	"revisions.diff_range.target_picker": {
		"target": "enum:to|from",
	},
	"revisions.duplicate.apply": {
		"force": "bool",
	},
	"revisions.duplicate.set_target": {
		"target": "enum:onto|after|before|insert",
	},
	"revisions.evolog.apply": {
		"force": "bool",
	},
	"revisions.inline_describe.accept": {
		"force": "bool",
	},
	"revisions.open_set_bookmark": {
		"value": "string",
	},
	"revisions.rebase.apply": {
		"force": "bool",
	},
	"revisions.rebase.set_source": {
		"source": "enum:revision|branch|source",
	},
	"revisions.rebase.set_target": {
		"target": "enum:onto|after|before|insert",
	},
	"revisions.revert.apply": {
		"force": "bool",
	},
	"revisions.revert.set_target": {
		"target": "enum:onto|after|before|insert",
	},
	"revisions.squash.apply": {
		"force": "bool",
	},
	"revisions.target_picker.apply": {
		"force": "bool",
	},
	"revset.edit": {
		"clear": "bool",
	},
	"revset.set": {
		"value": "string",
	},
	"ui.change_theme": {
		"name": "string",
	},
	"ui.preview.show": {
		"content": "string",
	},
}

var builtInActionRequiredArgs = map[string][]string{
	"diff.show":                          {"content"},
	"revisions.details.select_file":      {"file"},
	"revisions.diff_range.target_picker": {"target"},
	"revisions.duplicate.set_target":     {"target"},
	"revisions.rebase.set_source":        {"source"},
	"revisions.rebase.set_target":        {"target"},
	"revisions.revert.set_target":        {"target"},
	"revset.set":                         {"value"},
	"ui.change_theme":                    {"name"},
	"ui.preview.show":                    {"content"},
}

func ActionScopes(action string) []string {
	action = strings.TrimSpace(action)
	scopes, ok := builtInActionScopes[action]
	if !ok {
		return nil
	}
	return append([]string(nil), scopes...)
}

func ActionArgSchema(action string) map[string]string {
	return builtInActionArgSchemas[action]
}

func ActionRequiredArgs(action string) []string {
	return builtInActionRequiredArgs[action]
}

func BuiltInActions() []string {
	out := make([]string, 0, len(builtInActionScopes))
	for action := range builtInActionScopes {
		out = append(out, action)
	}
	sort.Strings(out)
	return out
}

func IsBuiltInAction(action string) bool {
	action = strings.TrimSpace(action)
	_, ok := builtInActionScopes[action]
	return ok
}

func ValidateBuiltInActionArgs(action string, args map[string]any) error {
	action = strings.TrimSpace(action)
	if !IsBuiltInAction(action) {
		return fmt.Errorf("unknown built-in action %q", action)
	}
	schema := builtInActionArgSchemas[action]
	for _, required := range builtInActionRequiredArgs[action] {
		if _, ok := args[required]; !ok {
			return fmt.Errorf("action %q requires arg %q", action, required)
		}
	}
	for key, value := range args {
		expectedType, ok := schema[key]
		if !ok {
			return fmt.Errorf("action %q does not accept arg %q", action, key)
		}
		switch expectedType {
		case "bool":
			if _, ok := value.(bool); !ok {
				return fmt.Errorf("action %q arg %q expects bool", action, key)
			}
		case "string":
			if _, ok := value.(string); !ok {
				return fmt.Errorf("action %q arg %q expects string", action, key)
			}
		default:
			if strings.HasPrefix(expectedType, "enum:") {
				s, ok := value.(string)
				if !ok {
					return fmt.Errorf("action %q arg %q expects string enum", action, key)
				}
				allowed := strings.Split(strings.TrimPrefix(expectedType, "enum:"), "|")
				valid := false
				for _, item := range allowed {
					if s == item {
						valid = true
						break
					}
				}
				if !valid {
					return fmt.Errorf("action %q arg %q invalid value %q (accepted: %s)", action, key, s, strings.Join(allowed, ", "))
				}
				continue
			}
			return fmt.Errorf("action %q arg %q has unsupported expected type %q", action, key, expectedType)
		}
	}
	return nil
}
