// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IOS_CHROME_BROWSER_INTELLIGENCE_FEATURES_FEATURES_H_
#define IOS_CHROME_BROWSER_INTELLIGENCE_FEATURES_FEATURES_H_

#import "base/feature_list.h"
#import "components/optimization_guide/proto/features/actions_data.pb.h"

namespace base {
class TimeDelta;
}  // namespace base

namespace optimization_guide::proto {
class Action;
}  // namespace optimization_guide::proto

class PrefService;

// Feature flag controlling whether enhanced calendar is enabled.
BASE_DECLARE_FEATURE(kEnhancedCalendar);

// Returns true if enhanced calendar is enabled.
bool IsEnhancedCalendarEnabled();

// Feature flag controlling the proactive suggestions framework.
BASE_DECLARE_FEATURE(kProactiveSuggestionsFramework);

// Returns true if the proactive suggestions framework is enabled.
bool IsProactiveSuggestionsFrameworkEnabled();

// Returns true if the popup blocker feature is enabled within the proactive
// suggestions framework.
bool IsProactiveSuggestionsFrameworkPopupBlockerEnabled();
extern const char kProactiveSuggestionsFrameworkPopupBlocker[];

// Page action menu feature flag, used to roll out and toggle in chrome://flags.
BASE_DECLARE_FEATURE(kPageActionMenu);

// Gemini killswitch, used to disable the feature in any locale, including
// launched ones.
BASE_DECLARE_FEATURE(kGeminiKillSwitch);

// TODO(crbug.com/494235953): Clean up when feature is enabled by default.
// Returns true if the page action menu is enabled.
bool IsPageActionMenuEnabled();

// Feature flag controlling the Ask Gemini auth flow in the Page Action Menu.
BASE_DECLARE_FEATURE(kPageActionMenuAuthFlow);

// Returns true if the Ask Gemini auth flow in the Page Action Menu is enabled.
bool IsPageActionMenuAuthFlowEnabled();

// Feature flag controlling if the Ask Gemini chip should ignore FET and time
// criteria.
BASE_DECLARE_FEATURE(kAskGeminiChipIgnoreCriteria);

// Returns true if the Ask Gemini chip should be shown without checking the FET
// and time criteria.
bool IsAskGeminiChipIgnoreCriteriaEnabled();

// Whether the omnibox entry point opens the BWG overlay immediately, skipping
// the AI hub.
bool IsDirectBWGEntryPoint();
extern const char kPageActionMenuDirectEntryPointParam[];

// Feature flag to enable Explain Gemini in Edit Menu.
BASE_DECLARE_FEATURE(kExplainGeminiEditMenu);

extern const char kExplainGeminiEditMenuParams[];

// Holds the position of Explain Gemini button in the EditMenu.
enum class PositionForExplainGeminiEditMenu {
  kDisabled = 0,
  kAfterEdit = 1,
  kAfterSearch = 2,
  kAdjacent = 3,
};

// Returns the position of Explain Gemini in the EditMenu.
PositionForExplainGeminiEditMenu ExplainGeminiEditMenuPosition();

// Feature flag to enable Precise Location in Gemini Settings Menu.
BASE_DECLARE_FEATURE(kGeminiPreciseLocation);

// Returns true if the precise location setting is enabled.
bool IsGeminiPreciseLocationEnabled();

// Feature flag to show the AI Hub new badge.
BASE_DECLARE_FEATURE(kAIHubNewBadge);
bool IsAIHubNewBadgeEnabled();

// Whether the Gemini consent pref should be deleted on account change.
bool ShouldDeleteGeminiConsentPref();

// Feature flag to delete the Gemini consent pref.
BASE_DECLARE_FEATURE(kDeleteGeminiConsentPref);

// Feature flag to enable smart tab grouping.
BASE_DECLARE_FEATURE(kSmartTabGrouping);

// Returns true if smart tab grouping is enabled.
bool IsSmartTabGroupingEnabled();

// Feature parameter determining the storage backend used for persisting tab
// contexts.
extern const char kPersistTabContextStorageParam[];

// Feature parameter detirmining the event(s) that trigger page context
// extraction.
extern const char kPersistTabContextExtractionTimingParam[];

// Feature parameter detirmining what page content data is persisted.
extern const char kPersistTabContextDataParam[];

// Defines the storage backend used for persisting tab contexts.
enum class PersistTabStorageType {
  kFileSystem = 0,
  kSQLite = 1,
};

// Defines the event(s) that trigger page context extraction.
enum class PersistTabExtractionTiming {
  kOnWasHidden = 0,
  kOnWasHiddenAndPageLoad = 1,
};

// Defines what page content data is persisted.
enum class PersistTabDataExtracted {
  kApcAndInnerText = 0,
  kInnerTextOnly = 1,
};

// Returns true if tab context persisting is enabled.
bool IsPersistTabContextEnabled();

// Returns the configured persistent tab context storage type.
PersistTabStorageType GetPersistTabContextStorageType();

// Returns the configured persistent tab context extraction timing.
PersistTabExtractionTiming GetPersistTabContextExtractionTiming();

// Returns the configured persistent tab context data extracted.
PersistTabDataExtracted GetPersistTabContextDataExtracted();

// Feature flag to persist tab context.
BASE_DECLARE_FEATURE(kPersistTabContext);

// Returns the effective Time-To-Live (TTL) for persisted tab contexts.
// This is the minimum of the `ttl_days` Finch parameter (with a default
// fallback if it is invalid) and the TTL defined by the Inactive Tabs feature.
base::TimeDelta GetPersistedContextEffectiveTTL(PrefService* prefs);

// Acts as a killswitch (enabled by default) for the
// PersistTabContextBrowserAgent.
BASE_DECLARE_FEATURE(kCleanupPersistedTabContexts);

// Returns true if persisted tab contexts cleanup is enabled.
bool IsCleanupPersistedTabContextsEnabled();

// Feature flag for the automatic Gemini promo shown on navigation.
BASE_DECLARE_FEATURE(kGeminiNavigationPromo);

// Returns true if the Gemini navigation promo is enabled.
bool IsGeminiNavigationPromoEnabled();

// Feature flag to enable zero-state suggestions.
BASE_DECLARE_FEATURE(kZeroStateSuggestions);

// Returns true if zero-state suggestions are enabled.
bool IsZeroStateSuggestionsEnabled();

// Feature flag to enable the 'What can Gemini do' static chip.
BASE_DECLARE_FEATURE(kZeroStateSuggestionsWCGD);

// Returns true if the 'What can Gemini do' static chip is enabled.
bool IsZeroStateSuggestionsWCGDEnabled();

// Feature flag to enable centralization of zero-state suggestions.
BASE_DECLARE_FEATURE(kZeroStateSuggestionsCentralization);

// Returns true if centralization of zero-state suggestions is enabled.
bool IsZeroStateSuggestionsCentralizationEnabled();

// Feature flag to use the new refactored version of the page context extractor.
// Acts as a killswitch where the feature is enabled by default.
BASE_DECLARE_FEATURE(kPageContextExtractorRefactored);

// Returns true if the refactored page context extractor is enabled.
bool IsPageContextExtractorRefactoredEnabled();

// Feature flag to enable the updated eligibility checks for Gemini.
BASE_DECLARE_FEATURE(kGeminiUpdatedEligibility);

// Returns true if the updated eligibiliy checks for Gemini are enabled.
bool IsGeminiUpdatedEligibilityEnabled();

// Feature flag to enable the updated Gemini consent.
BASE_DECLARE_FEATURE(kGeminiUpdatedConsent);

// Returns true if the updated Gemini consent is enabled.
bool IsGeminiUpdatedConsentEnabled();

// Feature flag for enabling the Gemini eligibility ablation experiment.
BASE_DECLARE_FEATURE(kGeminiEligibilityAblation);
bool IsGeminiEligibilityAblationEnabled();

// Feature flag for Gemini Live.
BASE_DECLARE_FEATURE(kGeminiLive);
bool IsGeminiLiveEnabled();

// Feature flag for Gemini Live Dormant Reasons.
BASE_DECLARE_FEATURE(kGeminiLiveDormantReasons);
bool IsGeminiLiveDormantReasonsEnabled();

// Returns true if the Gemini chat persistence is enabled.
bool IsGeminiChatPersistenceEnabled();
BASE_DECLARE_FEATURE(kGeminiChatPersistence);

// Feature flag for Gemini configurable parameters.
BASE_DECLARE_FEATURE(kGeminiConfigParams);

// The threshold interval for displaying the response ready state in seconds.
extern const char kGeminiResponseReadyInterval[];
double GetGeminiResponseReadyInterval();

// The Gemini session validity duration in minutes.
base::TimeDelta GetGeminiSessionValidityDuration();
extern const char kGeminiSessionValidityDuration[];


// Feature flag for Actor tools.
BASE_DECLARE_FEATURE(kActorTools);
bool IsActorEnabled();
extern const char kActorToolsPageStabilityParam[];
bool IsPageStabilityEnabled();
base::TimeDelta GetActorObservationDelayTimeout();
// Used to configure how long the PageStabilityMonitor in Chrome for iOS waits.
base::TimeDelta GetActorPageStabilityMinWait();
base::TimeDelta GetActorPageStabilityTimeout();
// The maximum number of mutations allowed within a post-interaction observation
// window for the page to be considered stable.
int GetActorPageStabilityMutationCap();
// The post-interaction observation window duration for page stability checking.
base::TimeDelta GetActorPageStabilityWindowDuration();
// The amount of time to wait for LCP if it hasn't occurred yet.
//
// Based on the Desktop equivalent at
// https://source.chromium.org/chromium/chromium/src/+/main:chrome/common/chrome_features.cc;l=422;drc=9c4f58fb857251ee67e9d98abcfcacef0500e51d.
base::TimeDelta GetActorPageStabilityLcpDelay();
// The amount of time to wait for Autofill to finish parsing and predicting form
// fields on the page.
//
// Based on the Desktop equivalent at
// https://source.chromium.org/chromium/chromium/src/+/main:chrome/common/chrome_features.cc;l=428;drc=9c4f58fb857251ee67e9d98abcfcacef0500e51d.
base::TimeDelta GetActorPageStabilityAutofillPredictionsTimeout();

// Returns true if the specified tool is disabled via the "DisabledTools"
// feature parameter of the `kActorTools` feature.
bool IsToolDisabled(optimization_guide::proto::Action::ActionCase tool);

// Feature flag for Model based page classification experiment.
BASE_DECLARE_FEATURE(kModelBasedPageClassification);

// Returns true if Model based page classification is enabled.
bool IsModelBasedPageClassificationEnabled();

// Returns the execution rate (0-100) for the classification experiment.
int GetModelBasedPageClassificationExecutionRate();

extern const char kModelBasedPageClassificationExecutionRateParam[];

// Enables the PageActionMenuIcon feature.
BASE_DECLARE_FEATURE(kPageActionMenuIcon);

// Param for the page action menu icon variations.
extern const char kPageActionMenuIconParams[];

// Icon to use for the page action menu entry point.
enum class PageActionMenuIconVariations {
  kDefault = 0,
  kSparkles1 = 1,
  kSparkles2 = 2,
};

PageActionMenuIconVariations GetPageActionMenuIcon();

// Feature flag for enabling Gemini backend migration.
BASE_DECLARE_FEATURE(kGeminiBackendMigration);
bool IsGeminiBackendMigrationEnabled();

// Feature flag for enabling Gemini actor.
BASE_DECLARE_FEATURE(kGeminiActor);
bool IsGeminiActorEnabled();

// Feature flag for enabling rich APC (v2) extraction for Gemini.
BASE_DECLARE_FEATURE(kGeminiRichAPCExtraction);
bool IsGeminiRichAPCExtractionEnabled();

// Enables the GeminiUnaryMigration feature.
BASE_DECLARE_FEATURE(kGeminiUnaryMigration);

// Returns true if the GeminiUnaryMigration feature is enabled.
bool IsGeminiUnaryMigrationEnabled();

// Enables the GeminiBinaryMigration feature.
BASE_DECLARE_FEATURE(kGeminiBinaryMigration);

// Returns true if the GeminiBinaryMigration feature is enabled.
bool IsGeminiBinaryMigrationEnabled();

// Enables the PageContextIPCOptimization feature.
BASE_DECLARE_FEATURE(kPageContextIPCOptimization);

// Returns true if the PageContextIPCOptimization feature is enabled.
bool IsPageContextIPCOptimizationEnabled();

// Returns true if the actionable optimization is enabled within the IPC
// optimization.
bool IsPageContextIPCOptimizationActionableEnabled();

// Enables the PageContextPdf feature. This allows PDFs to be used as context
// for prompts for Gemini only. Other providers would have separate flags.
BASE_DECLARE_FEATURE(kPageContextPdf);

// Returns true if the PageContextPdf feature is enabled.
bool IsPageContextPDFEnabled();

// Enables the GeminiClientMigration feature.
BASE_DECLARE_FEATURE(kGeminiClientMigration);

// Returns true if the GeminiClientMigration feature is enabled.
bool IsGeminiClientMigrationEnabled();

// Enables the GeminiMultiTabContext feature.
BASE_DECLARE_FEATURE(kGeminiMultiTabContext);

// Returns true if the GeminiMultiTabContext feature is enabled.
bool IsGeminiMultiTabContextEnabled();

// Enables the GeminiScreenContextMigration feature.
BASE_DECLARE_FEATURE(kGeminiScreenContextMigration);

// Returns true if the GeminiScreenContextMigration feature is enabled.
bool IsGeminiScreenContextMigrationEnabled();

// Feature flag to control the App Store In-App Events feature. Enables a
// user to tap the promo within the iOS App Store and invoke the Gemini FRE
// after navigating to a Gemini related web page through an external action.
BASE_DECLARE_FEATURE(kAppStoreInAppEvents);

// Returns true if the App Store In-App Events feature is enabled.
bool IsAppStoreInAppEventsEnabled();

// Feature flag controlling the generalized Gemini entry flow outside of the
// Page Action Menu.
BASE_DECLARE_FEATURE(kGeneralizedGeminiEntryFlow);

// Returns true if the generalized Gemini entry flow is enabled.
bool IsGeneralizedGeminiEntryFlowEnabled();

// Feature flag controlling Gemini Luminous.
BASE_DECLARE_FEATURE(kGeminiLuminous);

// Returns true if Gemini Luminous is enabled.
bool IsGeminiLuminousEnabled();

// Feature flag controlling App Switcher AI summarization.
BASE_DECLARE_FEATURE(kAppSwitcherAISummarization);

// Returns true if App Switcher AI summarization is enabled.
bool IsAppSwitcherAISummarizationEnabled();

// Feature flag controlling Gemini contextual suggestions cues framework.
BASE_DECLARE_FEATURE(kGeminiContextualSuggestionsCues);

// Returns true if Gemini contextual suggestions cues framework is enabled.
bool IsGeminiContextualSuggestionsCuesEnabled();

// Feature parameter for enabling on-device category classifier in Gemini
// contextual suggestions cues.
extern const char kGeminiContextualSuggestionsCuesOnDeviceClassifierParam[];

// Returns true if on-device category classifier is enabled for Gemini
// contextual suggestions cues.
bool IsGeminiContextualSuggestionsCuesOnDeviceClassifierEnabled();

// Feature parameter for allowing GPU / Neural Engine execution in Gemini
// contextual suggestions cues.
extern const char kGeminiContextualSuggestionsCuesAllowGpuExecutionParam[];

// Returns true if GPU / Neural Engine execution is allowed for Gemini
// contextual suggestions cues.
bool IsGeminiContextualSuggestionsCuesAllowGpuExecutionEnabled();

// Feature parameter for using Title and URL only (matching Desktop) for
// category classification.
extern const char kGeminiContextualSuggestionsCuesTitleAndUrlOnlyParam[];

// Returns true if category classification should only use Title and URL
// instead of extracting APC and generating passages.
bool IsGeminiContextualSuggestionsCuesTitleAndUrlOnlyEnabled();

#pragma mark - Debugging Features

// Holds the variations of the BWG Promo Consent flow for debugging.
enum class BWGPromoConsentVariations {
  kDisabled = 0,
  kSinglePage = 1,
  kDoublePage = 2,
  kSkipConsent = 3,
  kForceFRE = 4,
  kSkipNewUserDelay = 5,
};
extern const char kBWGPromoConsentParams[];

// Returns the variation of the BWG Promo Consent flow.
BWGPromoConsentVariations BWGPromoConsentVariationsParam();

// Returns YES if the promo should be forced.
bool ShouldForceBWGPromo();

// Returns YES if the Chrome FRE recency check should be skipped when evaluating
// whether to show the Gemini on-navigation promo.
bool ShouldSkipBWGPromoNewUserDelay();

// Feature flag to enable BWG Promo Consent for debugging.
BASE_DECLARE_FEATURE(kBWGPromoConsent);

// Feature flag to enable the ActorServiceLogging feature for debugging.
BASE_DECLARE_FEATURE(kActorServiceLogging);
bool IsActorServiceLoggingEnabled();

// Feature flag to enable the iOS bottom sheet migration.
BASE_DECLARE_FEATURE(kIOSGeminiBottomSheetMigration);

// Helper function to check if `kIOSGeminiBottomSheetMigration` is enabled.
bool IsIOSGeminiBottomSheetMigrationEnabled();

// Enables the GeminiQuizzes feature.
BASE_DECLARE_FEATURE(kGeminiQuizzes);

// Returns true if the GeminiQuizzes feature is enabled.
bool IsGeminiQuizzesEnabled();

// Feature flag to enable the Gemini FRE UI refactoring.
BASE_DECLARE_FEATURE(kGeminiFRERefactor);

// Helper function to check if `kGeminiFRERefactor` is enabled.
bool IsGeminiFRERefactorEnabled();

// Feature flag to control the Gemini coordinator teardown crash fix.
BASE_DECLARE_FEATURE(kGeminiCoordinatorTeardownFix);

// Returns true if the Gemini coordinator teardown crash fix is enabled.
bool IsGeminiCoordinatorTeardownFixEnabled();

// Feature flag to enable the Gemini FRE experiment.
BASE_DECLARE_FEATURE(kGeminiFREExperiment);

// Variations of the Lightweight FRE promo title/string.
enum class GeminiLightweightFREVariant {
  kConvenience = 0,
  kPageSharing = 1,
  kDiverse = 2,
};

// Feature parameter for Gemini FRE experiment variations.
extern const char kGeminiFREExperimentParam[];
extern const char kGeminiFREExperimentParamVisualRich[];
extern const char kGeminiFREExperimentParamLightweightConvenience[];
extern const char kGeminiFREExperimentParamLightweightPageSharing[];
extern const char kGeminiFREExperimentParamLightweightDiverse[];

// Returns true if the Gemini FRE experiment is enabled (any variation).
bool IsGeminiFREExperimentEnabled();

// Returns true if the Visual Rich variant is enabled.
bool IsGeminiVisualRichFREEnabled();

// Returns true if any Lightweight variant is enabled.
bool IsGeminiLightweightFREEnabled();

// Returns the specific Lightweight variant configured for the experiment.
GeminiLightweightFREVariant GetGeminiLightweightFREVariant();

// Feature flag for Gemini Experimental Guided Onboarding.
// Meant for experiments only.
BASE_DECLARE_FEATURE(kGeminiExperimentalGuidedOnboarding);

// Feature parameter to force Gemini Experimental Guided Onboarding for
// debugging.
extern const char kGeminiExperimentalGuidedOnboardingForceParam[];

// Returns true if Gemini Experimental Guided Onboarding is enabled.
bool IsGeminiExperimentalGuidedOnboardingEnabled();

// Returns true if Gemini Experimental Guided Onboarding should be forced for
// debugging.
bool ShouldForceGeminiExperimentalGuidedOnboarding();

// Controls whether blacked out bounding boxes for sensitive payment fields are
// applied to the screenshot in `PageContext`. Matches Blink's
// `kGlicScreenshotSensitivePaymentRedaction`.
// Note: When enabled, this feature enforces screenshot payment redactions on
// `PageContext` extractions that use rich extraction, overriding any local
// `PageContextWrapperConfig` setting. It has no effect on light extractions.
BASE_DECLARE_FEATURE(kPageContextScreenshotSensitivePaymentRedaction);

// Returns true if `kPageContextScreenshotSensitivePaymentRedaction` is enabled.
bool IsPageContextScreenshotSensitivePaymentRedactionEnabled();

// Controls whether Autofill credit card redactions are applied to clear
// sensitive field values in the `AnnotatedPageContent` (APC) proto. Matches
// Blink's `kAnnotatedPageContentAutofillCreditCardRedactions`.
// Note: When enabled, this feature enforces field value redactions on
// `PageContext` extractions that use rich extraction, overriding any local
// `PageContextWrapperConfig` setting. It has no effect on light extractions.
BASE_DECLARE_FEATURE(kPageContextAutofillCreditCardRedactions);

// Returns true if `kPageContextAutofillCreditCardRedactions` is
// enabled.
bool IsPageContextAutofillCreditCardRedactionsEnabled();

// Controls whether Autofill OTP redactions are applied to clear sensitive
// field values in the APC proto and screenshot. Matches Blink's
// `kAnnotatedPageContentAutofillOtpRedactions`.
// Note: When enabled, this feature enforces redactions on
// `PageContext` extractions that use rich extraction, overriding any local
// `PageContextWrapperConfig` setting. It has no effect on light extractions.
BASE_DECLARE_FEATURE(kPageContextAutofillOtpRedactions);

// Returns true if `kPageContextAutofillOtpRedactions` is enabled.
bool IsPageContextAutofillOtpRedactionsEnabled();

// Controls whether blacked out bounding boxes for password fields are applied
// to the screenshot in `PageContext`. Matches Blink's
// `kGlicScreenshotPasswordRedaction` behavior.
// Note: When enabled, this feature enforces screenshot password redactions on
// `PageContext` extractions that use rich extraction, overriding any local
// `PageContextWrapperConfig` setting. It has no effect on light extractions.
BASE_DECLARE_FEATURE(kPageContextScreenshotPasswordRedaction);

// Returns true if `kPageContextScreenshotPasswordRedaction` is enabled.
bool IsPageContextScreenshotPasswordRedactionEnabled();

// When enabled, the "Get insights with Gemini chip" is disabled.
BASE_DECLARE_FEATURE(kGeminiInsightsChipAblation);

// Returns true if the `GeminiInsightsChipAblation` feature is enabled.
bool IsGeminiInsightsChipAblationEnabled();

#endif  // IOS_CHROME_BROWSER_INTELLIGENCE_FEATURES_FEATURES_H_
