export const E2eTestId = {
  AgentsTable: "agents-table",
  CreateAgentButton: "create-agent-button",
  CreateAgentCloseHowToConnectButton: "create-agent-how-to-connect-button",
  CloneAgentButton: "clone-agent-button",
  DeleteAgentButton: "delete-agent-button",
  OnboardingNextButton: "onboarding-next-button",
  OnboardingSkipButton: "onboarding-skip-button",
  SignInSubmitButton: "sign-in-submit-button",
  InviteMemberButton: "invite-member-button",
  InviteEmailInput: "invite-email-input",
  InviteRoleSelect: "invite-role-select",
  GenerateInvitationButton: "generate-invitation-button",
  InvitationLinkInput: "invitation-link-input",
  InvitationLinkCopyButton: "invitation-link-copy-button",
  InvitationErrorMessage: "invitation-error-message",
  SidebarUserProfile: "sidebar-user-profile",
  SidebarNavGuardrails: "sidebar-nav-tool-guardrails",
  ManageCredentialsDialog: "manage-credentials-dialog",
  ManageCredentialsDialogTable: "manage-credentials-dialog-table",
  CredentialRow: "credential-row",
  CredentialOwner: "credential-owner",
  CredentialTeamSelect: "credential-team-select",
  ManageCredentialsButton: "manage-credentials-button",
  ConfigureIdpTeamSyncButton: "configure-idp-team-sync-button",
  IdentityProviderCard: "identity-provider-card",
  IdentityProviderOpenDialogButton: "identity-provider-open-dialog-button",
  IdentityProviderCreateButton: "identity-provider-create-button",
  IdentityProviderUpdateButton: "identity-provider-update-button",
  IdentityProviderDeleteButton: "identity-provider-delete-button",
  IdentityProviderDialogNavButton: "identity-provider-dialog-nav-button",
  IdpRoleMappingAccordionTrigger: "idp-role-mapping-accordion-trigger",
  IdpRoleMappingDefaultRole: "idp-role-mapping-default-role",
  IdpRoleMappingRuleRole: "idp-role-mapping-rule-role",
  IdpRoleMappingRuleTemplate: "idp-role-mapping-rule-template",
  IdpRoleMappingAddRule: "idp-role-mapping-add-rule",
  McpServerError: "mcp-server-error",
  McpServerCard: "mcp-server-card",
  McpServerSettingsButton: "mcp-server-settings-button",
  McpServerToolsCount: "mcp-server-tools-count",
  McpToolsDialog: "mcp-tools-dialog",
  TokenSelect: "token-select",
  ProfileTokenManagerTeamsSelect: "profile-token-manager-teams-select",
  ConnectAgentButton: "connect-agent-button",
  ConnectCatalogItemButton: "connect-catalog-item-button",
  SelectCredentialTypePersonal: "select-credential-type-personal",
  CredentialsCount: "credentials-count",
  StaticCredentialToUse: "static-credential-to-use",
  SelectCredentialTypeTeamDropdown: "select-credential-type-team-dropdown",
  ProfileTeamBadge: "profile-team-badge",
  EditAgentButton: "edit-agent-button",
  AgentCapabilitiesSection: "agent-capabilities-section",
  AgentToolsAddButton: "agent-tools-add-button",
  AgentToolCatalogPill: "agent-tool-catalog-pill",
  AssignmentComboboxSearchInput: "assignment-combobox-search-input",
  AssignmentComboboxOption: "assignment-combobox-option",
  AssignmentComboboxDisabledOption: "assignment-combobox-disabled-option",
  RemoveTeamBadge: "remove-team-badge",
  PromptOnInstallationCheckbox: "prompt-on-installation-checkbox",
  RevokeCredentialButton: "revoke-credential-button",
  ExternalSecretSelector: "external-secret-selector",
  SelectEnvironmentVariableType: "select-environment-variable-type",
  SelectEnvironment: "select-environment",
  AddCatalogItemButton: "add-catalog-item-button",
  ConfigureVaultFolderButton: "configure-vault-folder-button",
  ExternalSecretSelectorTeamTrigger: "external-secret-selector-team-trigger",
  ExternalSecretSelectorSecretTrigger:
    "external-secret-selector-secret-trigger",
  ExternalSecretSelectorSecretTriggerKey:
    "external-secret-selector-secret-trigger-key",
  InlineVaultSecretSelectorSecretTrigger:
    "inline-vault-secret-selector-secret-trigger",
  InlineVaultSecretSelectorSecretTriggerKey:
    "inline-vault-secret-selector-secret-trigger-key",
  McpServerSettingsConnectionsNavButton:
    "mcp-server-settings-connections-nav-button",
  McpServerSettingsConnectionsContent:
    "mcp-server-settings-connections-content",
  ManageCredentialsSharedConnectionsSection:
    "manage-credentials-shared-connections-section",
  ManageCredentialsSharedConnectionsEmptyState:
    "manage-credentials-shared-connections-empty-state",
  ManageCredentialsAddToOrgButton: "manage-credentials-add-to-org-button",
  ManageCredentialsAddToTeamButton: "manage-credentials-add-to-team-button",
  ManageCredentialsAddToTeamOption: "manage-credentials-add-to-team-option",
  ManageCredentialsAddServiceAccountButton:
    "manage-credentials-add-service-account-button",
  AddServiceAccountConfirmButton: "add-service-account-confirm-button",
  ManageServiceAccountsTable: "manage-service-accounts-table",
  ManageMembersButton: "manage-members-button",
  // Chat Settings
  ChatApiKeysTable: "chat-api-keys-table",
  AddChatApiKeyButton: "add-chat-api-key-button",
  ChatApiKeyRow: "chat-api-key-row",
  ChatApiKeyForm: "chat-api-key-form",
  EditChatApiKeyButton: "edit-chat-api-key-button",
  DeleteChatApiKeyButton: "delete-chat-api-key-button",
  SetDefaultChatApiKeyButton: "set-default-chat-api-key-button",
  ManageProfilesChatApiKeyButton: "manage-profiles-chat-api-key-button",
  ChatApiKeyDefaultBadge: "chat-api-key-default-badge",
  BulkAssignChatApiKeysButton: "bulk-assign-chat-api-keys-button",
  BulkAssignChatApiKeysDialog: "bulk-assign-chat-api-keys-dialog",
  VirtualKeysPage: "virtual-keys-page",
  VirtualKeysTable: "virtual-keys-table",
  AddVirtualKeyButton: "add-virtual-key-button",
  VirtualKeyCreateDialog: "virtual-key-create-dialog",
  VirtualKeyDeleteDialog: "virtual-key-delete-dialog",
  VirtualKeyProviderSelect: "virtual-key-provider-select",
  VirtualKeyParentKeySelect: "virtual-key-parent-key-select",
  VirtualKeyValue: "virtual-key-value",
  // Chat Prompt Input
  ChatFileUploadButton: "chat-file-upload-button",
  ChatDisabledFileUploadButton: "chat-disabled-file-upload-button",
  ChatContextUsageTrigger: "chat-context-usage-trigger",
  ChatContextUsagePanel: "chat-context-usage-panel",
  ChatApiKeySelectorTrigger: "chat-api-key-selector-trigger",
  ChatApiKeySelectorSearchInput: "chat-api-key-selector-search-input",
  // Chat Model Selector
  ChatModelSelectorTrigger: "chat-model-selector-trigger",
  ChatPromptTextarea: "chat-prompt-textarea",
  // Chat sidebar item status indicators
  ChatItemGeneratingIndicator: "chat-item-generating-indicator",
  ChatItemUnreadIndicator: "chat-item-unread-indicator",
  QuickstartAddApiKeyButton: "quickstart-add-api-key-button",
  // First-run "set a default model" onboarding nudge (after the first key)
  OnboardingDefaultModelOpen: "onboarding-default-model-open",
  OnboardingDefaultModelSkip: "onboarding-default-model-skip",
  OnboardingDefaultModelSubmit: "onboarding-default-model-submit",
  ApiKeysLoadErrorRetry: "api-keys-load-error-retry",
  // MCP Logs
  McpLogsDialog: "mcp-logs-dialog",
  McpLogsContent: "mcp-logs-content",
  McpLogsError: "mcp-logs-error",
  McpLogsViewButton: "mcp-logs-view-button",
  McpLogsEditConfigButton: "mcp-logs-edit-config-button",
  McpLogsTab: "mcp-logs-tab",
  // Connectivity / offline status bar
  ConnectivityStatusBar: "connectivity-status-bar",
  ConnectivityStatusBarRetry: "connectivity-status-bar-retry",
  // Role debugger / impersonation
  ImpersonationBanner: "impersonation-banner",
  ImpersonationStopButton: "impersonation-stop-button",
  ImpersonationViewAsButton: "impersonation-view-as-button",
} as const;

export type E2eTestId = (typeof E2eTestId)[keyof typeof E2eTestId];

export function getIdpRoleMappingRuleRowTestId(index: number): string {
  return `role-mapping-rule-${index}`;
}

export function getIdentityProviderDialogNavButtonTestId(
  section: string,
): string {
  return `${E2eTestId.IdentityProviderDialogNavButton}-${section}`;
}

export function getChatApiKeySelectorProviderGroupTestId(
  provider: string,
): string {
  return `chat-api-key-selector-provider-${provider}`;
}

export function getChatItemGeneratingIndicatorTestId(
  conversationId: string,
): string {
  return `${E2eTestId.ChatItemGeneratingIndicator}-${conversationId}`;
}

export function getChatItemUnreadIndicatorTestId(
  conversationId: string,
): string {
  return `${E2eTestId.ChatItemUnreadIndicator}-${conversationId}`;
}

export function getChatApiKeySelectorOptionTestId(keyId: string): string {
  return `chat-api-key-selector-option-${keyId}`;
}

export function getVirtualKeyRowTestId(keyName: string): string {
  return `virtual-key-row-${keyName}`;
}

export function getDeleteVirtualKeyButtonTestId(keyName: string): string {
  return `delete-virtual-key-button-${keyName}`;
}

export function getAgentToolCatalogPillTestId(catalogItemName: string): string {
  return `${E2eTestId.AgentToolCatalogPill}-${catalogItemName}`;
}

export function getManageCredentialsButtonTestId(
  catalogItemName: string,
): string {
  return `${E2eTestId.ManageCredentialsButton}-${catalogItemName}`;
}

export function getAssignmentComboboxSearchInputTestId(
  comboboxTestId: string,
): string {
  return `${E2eTestId.AssignmentComboboxSearchInput}-${comboboxTestId}`;
}

export function getAssignmentComboboxOptionTestId(
  comboboxTestId: string,
  itemName: string,
): string {
  return `${E2eTestId.AssignmentComboboxOption}-${comboboxTestId}-${itemName}`;
}

export function getAssignmentComboboxDisabledOptionTestId(
  comboboxTestId: string,
  itemName: string,
): string {
  return `${E2eTestId.AssignmentComboboxDisabledOption}-${comboboxTestId}-${itemName}`;
}

export function getManageCredentialsAddToTeamOptionTestId(
  teamName: string,
): string {
  return `${E2eTestId.ManageCredentialsAddToTeamOption}-${teamName}`;
}
