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

#ifndef COMPONENTS_SEARCH_ENGINES_SEARCH_ENGINES_TEST_UTIL_H_
#define COMPONENTS_SEARCH_ENGINES_SEARCH_ENGINES_TEST_UTIL_H_

#include <memory>
#include <string>

#include "base/time/time.h"
#include "components/search_engines/search_engine_choice/search_engine_choice_service.h"

struct TemplateURLData;

namespace sync_preferences {
class TestingPrefServiceSyncable;
}

// Generates a TemplateURLData structure useful for tests filled with values
// autogenerated from |provider_name|.
std::unique_ptr<TemplateURLData> GenerateDummyTemplateURLData(
    const std::string& keyword);

// Checks that the two TemplateURLs are similar. Does not check the id, the
// date_created or the last_modified time.  Neither pointer should be null.
void ExpectSimilar(const TemplateURLData* expected,
                   const TemplateURLData* actual);

// Writes default search engine |extension_data| into the extension-controlled
// preference in |prefs|.
void SetExtensionDefaultSearchInPrefs(
    sync_preferences::TestingPrefServiceSyncable* prefs,
    const TemplateURLData& extension_data);

// Removes the extension-controlled default search engine preference from
// |prefs|.
void RemoveExtensionDefaultSearchFromPrefs(
    sync_preferences::TestingPrefServiceSyncable* prefs);

class FakeSearchEngineChoiceServiceClient
    : public search_engines::SearchEngineChoiceService::Client {
 public:
  explicit FakeSearchEngineChoiceServiceClient(
      country_codes::CountryId variations_country = country_codes::CountryId(),
      bool is_profile_eligible_for_dse_guest_propagation = false,
      bool is_device_restore_detected_in_current_session = false,
      bool does_choice_predate_device_restore = false);
  ~FakeSearchEngineChoiceServiceClient() override;

  // `SearchEngineChoiceService::Client` implementation.
  country_codes::CountryId GetVariationsCountry() override;
  bool IsProfileEligibleForDseGuestPropagation() override;
  bool IsDeviceRestoreDetectedInCurrentSession() override;
  bool DoesChoicePredateDeviceRestore(
      const search_engines::ChoiceCompletionMetadata& choice_metadata) override;

  void set_variations_country(country_codes::CountryId variations_country) {
    variations_country_ = variations_country;
  }

  void set_is_profile_eligible_for_dse_guest_propagation(bool eligible) {
    is_profile_eligible_for_dse_guest_propagation_ = eligible;
  }

  void set_is_device_restore_detected_in_current_session(bool is_detected) {
    is_device_restore_detected_in_current_session_ = is_detected;
  }

  void set_does_choice_predate_device_restore(bool does_predate) {
    does_choice_predate_device_restore_ = does_predate;
  }

  void set_restore_detection_time(base::Time restore_detection_time) {
    restore_detection_time_ = restore_detection_time;
  }

 private:
  country_codes::CountryId variations_country_;
  bool is_profile_eligible_for_dse_guest_propagation_ = false;
  bool is_device_restore_detected_in_current_session_ = false;
  bool does_choice_predate_device_restore_ = false;
  std::optional<base::Time> restore_detection_time_;
};

#endif  // COMPONENTS_SEARCH_ENGINES_SEARCH_ENGINES_TEST_UTIL_H_
