/*
 * Copyright (c) 2020-2025, WSO2 LLC. (http://www.wso2.com).
 *
 * WSO2 LLC. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.wso2.carbon.identity.api.server.configs.common;

import org.wso2.carbon.base.api.ServerConfigurationService;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.application.authentication.framework.services.ConsentAppMappingService;
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
import org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService;
import org.wso2.carbon.identity.compatibility.settings.core.service.CompatibilitySettingsService;
import org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager;
import org.wso2.carbon.identity.cors.mgt.core.CORSManagementService;
import org.wso2.carbon.identity.fraud.detection.core.service.FraudDetectionConfigsService;
import org.wso2.carbon.identity.notification.push.device.handler.DeviceHandlerService;
import org.wso2.carbon.identity.oauth.dcr.DCRConfigurationMgtService;
import org.wso2.carbon.identity.oauth2.agent.services.AgentConfigMgtService;
import org.wso2.carbon.identity.oauth2.config.services.OAuth2OIDCConfigOrgUsageScopeMgtService;
import org.wso2.carbon.identity.oauth2.fapi.services.FapiConfigMgtService;
import org.wso2.carbon.identity.oauth2.impersonation.services.ImpersonationConfigMgtService;
import org.wso2.carbon.identity.oauth2.token.handler.clientauth.jwt.core.JWTClientAuthenticatorMgtService;
import org.wso2.carbon.idp.mgt.IdentityProviderManager;
import org.wso2.carbon.idp.mgt.IdpManager;
import org.wso2.carbon.logging.service.RemoteLoggingConfigService;

/**
 * Service holder class for server configuration related services.
 */
public class ConfigsServiceHolder {

    private ConfigsServiceHolder() {}

    private static class ApplicationManagementServiceHolder {

        static final ApplicationManagementService SERVICE = (ApplicationManagementService) PrivilegedCarbonContext
                .getThreadLocalCarbonContext().getOSGiService(ApplicationManagementService.class, null);
    }

    private static class IdentityProviderManagerHolder {

        static final IdentityProviderManager SERVICE = (IdentityProviderManager) PrivilegedCarbonContext
                .getThreadLocalCarbonContext().getOSGiService(IdpManager.class, null);
    }

    private static class CORSManagementServiceHolder {

        static final CORSManagementService SERVICE = (CORSManagementService) PrivilegedCarbonContext
                .getThreadLocalCarbonContext().getOSGiService(CORSManagementService.class, null);
    }

    private static class RemoteLoggingConfigServiceHolder {

        static final RemoteLoggingConfigService SERVICE = (RemoteLoggingConfigService) PrivilegedCarbonContext
                .getThreadLocalCarbonContext().getOSGiService(RemoteLoggingConfigService.class, null);
    }

    private static class ImpersonationConfigMgtServiceHolder {

        static final ImpersonationConfigMgtService SERVICE = (ImpersonationConfigMgtService) PrivilegedCarbonContext
                .getThreadLocalCarbonContext().getOSGiService(ImpersonationConfigMgtService.class, null);
    }

    private static class AgentConfigMgtServiceHolder {

        static final AgentConfigMgtService SERVICE = (AgentConfigMgtService) PrivilegedCarbonContext
                .getThreadLocalCarbonContext().getOSGiService(AgentConfigMgtService.class, null);
    }

    private static class DCRConfigurationMgtServiceHolder {

        static final DCRConfigurationMgtService SERVICE = (DCRConfigurationMgtService) PrivilegedCarbonContext
                .getThreadLocalCarbonContext().getOSGiService(DCRConfigurationMgtService.class, null);
    }

    private static class JWTClientAuthenticatorMgtServiceHolder {

        static final JWTClientAuthenticatorMgtService SERVICE =
                (JWTClientAuthenticatorMgtService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
                        .getOSGiService(JWTClientAuthenticatorMgtService.class, null);
    }

    private static class ServerConfigurationServiceHolder {

        static final ServerConfigurationService SERVICE =
                (ServerConfigurationService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
                        .getOSGiService(ServerConfigurationService.class, null);
    }

    private static class ClaimMetaDataManagementServiceHolder {

        static final ClaimMetadataManagementService SERVICE =
                (ClaimMetadataManagementService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
                        .getOSGiService(ClaimMetadataManagementService.class, null);
    }

    private static class FraudDetectionConfigsServiceHolder {

        static final FraudDetectionConfigsService SERVICE =
                (FraudDetectionConfigsService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
                        .getOSGiService(FraudDetectionConfigsService.class, null);
    }

    private static class OAuth2OIDCConfigOrgUsageScopeMgtServiceHolder {

        static final OAuth2OIDCConfigOrgUsageScopeMgtService SERVICE =
                (OAuth2OIDCConfigOrgUsageScopeMgtService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
                        .getOSGiService(OAuth2OIDCConfigOrgUsageScopeMgtService.class, null);
    }

    private static class IdentityCompatibilitySettingsServiceHolder {

        static final CompatibilitySettingsService SERVICE =
                (CompatibilitySettingsService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
                        .getOSGiService(CompatibilitySettingsService.class, null);
    }

    private static class PushDeviceHandlerServiceHolder {

        static final DeviceHandlerService SERVICE =
                (DeviceHandlerService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
                        .getOSGiService(DeviceHandlerService.class, null);
    }

    private static class ConfigurationManagerHolder {

        static final ConfigurationManager SERVICE =
                (ConfigurationManager) PrivilegedCarbonContext.getThreadLocalCarbonContext()
                        .getOSGiService(ConfigurationManager.class, null);
    }

    private static class ConsentAppMappingServiceHolder {

        static final ConsentAppMappingService SERVICE =
                (ConsentAppMappingService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
                        .getOSGiService(ConsentAppMappingService.class, null);
    }

    private static class FapiConfigMgtServiceHolder {

        static final FapiConfigMgtService SERVICE =
                (FapiConfigMgtService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
                        .getOSGiService(FapiConfigMgtService.class, null);
    }

    /**
     * Get ApplicationManagementService osgi service.
     *
     * @return ApplicationManagementService
     */
    public static ApplicationManagementService getApplicationManagementService() {

        return ApplicationManagementServiceHolder.SERVICE;
    }

    /**
     * Get IdentityProviderManager osgi service.
     *
     * @return IdentityProviderManager
     */
    public static IdentityProviderManager getIdentityProviderManager() {

        return IdentityProviderManagerHolder.SERVICE;
    }

    /**
     * Get CORSManagementService osgi service.
     *
     * @return CORSManagementService
     */
    public static CORSManagementService getCorsManagementService() {

        return CORSManagementServiceHolder.SERVICE;
    }

    /**
     * Get RemoteLoggingConfigService osgi service.
     *
     * @return RemoteLoggingConfigService
     */
    public static RemoteLoggingConfigService getRemoteLoggingConfigService() {

        return RemoteLoggingConfigServiceHolder.SERVICE;
    }

    /**
     * Get Impersonation Config Mgt osgi service.
     *
     * @return RemoteLoggingConfigService
     */
    public static ImpersonationConfigMgtService getImpersonationConfigMgtService() {

        return ImpersonationConfigMgtServiceHolder.SERVICE;
    }

    /**
     * Get Agent Config Mgt osgi service.
     *
     * @return AgentConfigMgtService
     */
    public static AgentConfigMgtService getAgentConfigMgtService() {

        return AgentConfigMgtServiceHolder.SERVICE;
    }

    /**
     * Get DCRConfigurationMgtService osgi service.
     *
     * @return DCRConfigurationMgtService
     */
    public static DCRConfigurationMgtService getDcrConfigurationMgtService() {

        return DCRConfigurationMgtServiceHolder.SERVICE;
    }

    /**
     * Get JWTClientAuthenticatorMgtService osgi service.
     *
     * @return JWTClientAuthenticatorMgtService
     */
    public static JWTClientAuthenticatorMgtService getJWTClientAuthenticatorMgtService() {

        return JWTClientAuthenticatorMgtServiceHolder.SERVICE;
    }

    /**
     * Get ServerConfigurationService osgi service.
     *
     * @return ServerConfigurationService
     */
    public static ServerConfigurationService getServerConfigurationService() {

        return ServerConfigurationServiceHolder.SERVICE;
    }

    /**
     * Get ClaimMetadataManagementService osgi service.
     *
     * @return ClaimMetadataManagementService
     */
    public static ClaimMetadataManagementService getClaimMetadataManagementService() {

        return ClaimMetaDataManagementServiceHolder.SERVICE;
    }

    /**
     * Get FraudDetectionConfigsService osgi service.
     *
     * @return FraudDetectionConfigsService
     */
    public static FraudDetectionConfigsService getFraudDetectionConfigsService() {

        return FraudDetectionConfigsServiceHolder.SERVICE;
    }

    /**
     * Get OAuth2OIDCConfigOrgUsageScopeMgtService osgi service.
     *
     * @return OAuth2OIDCConfigOrgUsageScopeMgtService
     */
    public static OAuth2OIDCConfigOrgUsageScopeMgtService getOAuth2OIDCConfigOrgUsageScopeMgtService() {

        return OAuth2OIDCConfigOrgUsageScopeMgtServiceHolder.SERVICE;
    }

    /**
     * Get IdentityCompatibilitySettingsService osgi service.
     *
     * @return IdentityCompatibilitySettingsService
     */
    public static CompatibilitySettingsService getIdentityCompatibilitySettingsService() {

        return IdentityCompatibilitySettingsServiceHolder.SERVICE;
    }

    /**
     * Get DeviceHandlerService osgi service.
     *
     * @return DeviceHandlerService
     */
    public static DeviceHandlerService getPushDeviceHandlerService() {

        return PushDeviceHandlerServiceHolder.SERVICE;
    }

    /**
     * Get ConfigurationManager osgi service.
     *
     * @return ConfigurationManager
     */
    public static ConfigurationManager getConfigurationManager() {

        return ConfigurationManagerHolder.SERVICE;
    }

    /**
     * Get ConsentAppMappingService osgi service.
     *
     * @return ConsentAppMappingService
     */
    public static ConsentAppMappingService getConsentAppMappingService() {

        return ConsentAppMappingServiceHolder.SERVICE;
    }

    /**
     * Get FapiConfigMgtService osgi service.
     *
     * @return FapiConfigMgtService
     */
    public static FapiConfigMgtService getFapiConfigMgtService() {

        return FapiConfigMgtServiceHolder.SERVICE;
    }
}
