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

#import "ios/chrome/browser/enterprise/model/idle/idle_timeout_policy_utils.h"

#import "components/enterprise/idle/action_type.h"
#import "components/prefs/pref_service.h"
#import "components/signin/public/base/consent_level.h"
#import "components/signin/public/identity_manager/identity_manager.h"

namespace enterprise_idle {

ActionSet GetActionSet(PrefService* prefs,
                       signin::IdentityManager* identity_manager) {
  std::vector<ActionType> action_types = GetActionTypesFromPrefs(prefs);
  ActionSet action_set;
  for (ActionType action_type : action_types) {
    switch (action_type) {
      case ActionType::kCloseTabs:
        action_set.close = true;
        break;

        // The dialog and snackbar should not say "signed out" if the user was
        // not signed in before actions run.
      case ActionType::kSignOut:
        action_set.signout =
            identity_manager->HasPrimaryAccount(signin::ConsentLevel::kSignin);
        break;

      case ActionType::kClearBrowsingHistory:
      case ActionType::kClearCookiesAndOtherSiteData:
      case ActionType::kClearCachedImagesAndFiles:
      case ActionType::kClearPasswordSignin:
      case ActionType::kClearAutofill:
        action_set.clear = true;
        break;
    }
  }
  return action_set;
}

}  // namespace enterprise_idle
