// Copyright 2026 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/level_up/model/level_up_service_factory.h"

#import "base/no_destructor.h"
#import "ios/chrome/browser/level_up/model/level_up_service.h"
#import "ios/chrome/browser/passwords/model/ios_chrome_password_check_manager.h"
#import "ios/chrome/browser/passwords/model/ios_chrome_password_check_manager_factory.h"
#import "ios/chrome/browser/sessions/model/session_restoration_service_factory.h"
#import "ios/chrome/browser/shared/model/browser/browser_list_factory.h"
#import "ios/chrome/browser/shared/model/profile/profile_ios.h"

// static
LevelUpService* LevelUpServiceFactory::GetForProfile(ProfileIOS* profile) {
  return GetInstance()->GetServiceForProfileAs<LevelUpService>(profile,
                                                               /*create=*/true);
}

// static
LevelUpServiceFactory* LevelUpServiceFactory::GetInstance() {
  static base::NoDestructor<LevelUpServiceFactory> instance;
  return instance.get();
}

LevelUpServiceFactory::LevelUpServiceFactory()
    : ProfileKeyedServiceFactoryIOS("LevelUpService") {
  DependsOn(BrowserListFactory::GetInstance());
  DependsOn(SessionRestorationServiceFactory::GetInstance());
  DependsOn(IOSChromePasswordCheckManagerFactory::GetInstance());
}

LevelUpServiceFactory::~LevelUpServiceFactory() {}

std::unique_ptr<KeyedService> LevelUpServiceFactory::BuildServiceInstanceFor(
    ProfileIOS* profile) const {
  BrowserList* browser_list = BrowserListFactory::GetForProfile(profile);
  SessionRestorationService* session_restoration_service =
      SessionRestorationServiceFactory::GetForProfile(profile);
  scoped_refptr<IOSChromePasswordCheckManager> password_check_manager =
      IOSChromePasswordCheckManagerFactory::GetForProfile(profile);
  return std::make_unique<LevelUpService>(profile->GetPrefs(), browser_list,
                                          session_restoration_service,
                                          password_check_manager.get());
}
