// Path: src/main/java/com/epam/reportportal/auth/integration/AuthIntegrationType.java
// public enum AuthIntegrationType {
// 
// 	ACTIVE_DIRECTORY("ad") {
// 		@Override
// 		public Optional<Integration> get(Integration entity) {
// 			return ofNullable(entity);
// 		}
// 
// 		@Override
// 		public Function<Integration, ActiveDirectoryResource> getToResourceMapper() {
// 			return ActiveDirectoryConverter.TO_RESOURCE;
// 		}
// 	},
// 	LDAP("ldap") {
// 		@Override
// 		public Optional<Integration> get(Integration entity) {
// 			return ofNullable(entity);
// 		}
// 
// 		@Override
// 		public Function<Integration, LdapResource> getToResourceMapper() {
// 			return LdapConverter.TO_RESOURCE;
// 		}
// 	},
// 	SAML("saml") {
// 		@Override
// 		public Optional<Integration> get(Integration entity) {
// 			return ofNullable(entity);
// 		}
// 
// 		@Override
// 		public Function<Integration, SamlResource> getToResourceMapper() {
// 			return SamlConverter.TO_RESOURCE;
// 		}
// 	};
// 
// 	private String name;
// 
// 	AuthIntegrationType(String name) {
// 		this.name = name;
// 	}
// 
// 	public abstract Optional<Integration> get(Integration entity);
// 
// 	public abstract Function<Integration, ? extends AbstractAuthResource> getToResourceMapper();
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public static Optional<AuthIntegrationType> fromId(String id) {
// 		return Arrays.stream(values()).filter(it -> it.name.equalsIgnoreCase(id)).findAny();
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return this.name;
// 	}
// }
// 
// Path: src/main/java/com/epam/reportportal/auth/integration/handler/CreateAuthIntegrationHandler.java
// public interface CreateAuthIntegrationHandler {
// 
// 	AbstractAuthResource createAuthIntegration(AuthIntegrationType type, UpdateAuthRQ request, ReportPortalUser user);
// 
// 	AbstractAuthResource updateAuthIntegration(AuthIntegrationType type, Long integrationId, UpdateAuthRQ request, ReportPortalUser user);
// 
// 	OAuthRegistrationResource createOrUpdateOauthSettings(String oauthProviderId, OAuthRegistrationResource clientRegistrationResource);
// }
// 
// Path: src/main/java/com/epam/reportportal/auth/integration/handler/DeleteAuthIntegrationHandler.java
// public interface DeleteAuthIntegrationHandler {
// 
// 	OperationCompletionRS deleteAuthIntegrationById(Long integrationId);
// 
// 	OperationCompletionRS deleteOauthSettingsById(String oauthProviderId);
// }
// 
// Path: src/main/java/com/epam/reportportal/auth/integration/handler/GetAuthIntegrationHandler.java
// public interface GetAuthIntegrationHandler {
// 
// 	AbstractAuthResource getIntegrationByType(AuthIntegrationType integrationType);
// 
// 	Map<String, OAuthRegistrationResource> getAllOauthIntegrations();
// 
// 	OAuthRegistrationResource getOauthIntegrationById(String oauthProviderId);
// }


import com.epam.reportportal.auth.integration.AuthIntegrationType;
import com.epam.reportportal.auth.integration.handler.CreateAuthIntegrationHandler;
import com.epam.reportportal.auth.integration.handler.DeleteAuthIntegrationHandler;
import com.epam.reportportal.auth.integration.handler.GetAuthIntegrationHandler;
import com.epam.ta.reportportal.commons.ReportPortalUser;
import com.epam.ta.reportportal.exception.ReportPortalException;
import com.epam.ta.reportportal.ws.model.ErrorType;
import com.epam.ta.reportportal.ws.model.OperationCompletionRS;
import com.epam.ta.reportportal.ws.model.integration.auth.AbstractAuthResource;
import com.epam.ta.reportportal.ws.model.integration.auth.UpdateAuthRQ;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.beans.PropertyEditorSupport;
	@PostMapping(value = "/{authType}")
	@ResponseStatus(HttpStatus.OK)
	@ApiOperation(value = "Create new auth integration")
	public AbstractAuthResource createAuthIntegration(@RequestBody @Valid UpdateAuthRQ request, @AuthenticationPrincipal ReportPortalUser user,
			@PathVariable AuthIntegrationType authType) {
		return createAuthIntegrationHandler.createAuthIntegration(authType, request, user);
	}

	/**
	 * Creates or updates auth integration settings
	 *
	 * @param request Update request
	 * @return Successful message or an error
	 */
	@Transactional
	@PutMapping(value = "/{authType}/{integrationId}")
	@ResponseStatus(HttpStatus.OK)
	@ApiOperation(value = "Update auth integration")
	public AbstractAuthResource updateAuthIntegration(@RequestBody @Valid UpdateAuthRQ request, @AuthenticationPrincipal ReportPortalUser user,
			@PathVariable AuthIntegrationType authType, @PathVariable Long integrationId) {
		return createAuthIntegrationHandler.updateAuthIntegration(authType, integrationId, request, user);
	}

	/**
	 * Get auth settings by type
	 *
	 * @param authType Type of Auth
	 * @return Successful message or an error
	 */
	@Transactional(readOnly = true)
// Path: src/main/java/com/epam/reportportal/auth/integration/AuthIntegrationType.java
// public enum AuthIntegrationType {
// 
// 	ACTIVE_DIRECTORY("ad") {
// 		@Override
// 		public Optional<Integration> get(Integration entity) {
// 			return ofNullable(entity);
// 		}
// 
// 		@Override
// 		public Function<Integration, ActiveDirectoryResource> getToResourceMapper() {
// 			return ActiveDirectoryConverter.TO_RESOURCE;
// 		}
// 	},
// 	LDAP("ldap") {
// 		@Override
// 		public Optional<Integration> get(Integration entity) {
// 			return ofNullable(entity);
// 		}
// 
// 		@Override
// 		public Function<Integration, LdapResource> getToResourceMapper() {
// 			return LdapConverter.TO_RESOURCE;
// 		}
// 	},
// 	SAML("saml") {
// 		@Override
// 		public Optional<Integration> get(Integration entity) {
// 			return ofNullable(entity);
// 		}
// 
// 		@Override
// 		public Function<Integration, SamlResource> getToResourceMapper() {
// 			return SamlConverter.TO_RESOURCE;
// 		}
// 	};
// 
// 	private String name;
// 
// 	AuthIntegrationType(String name) {
// 		this.name = name;
// 	}
// 
// 	public abstract Optional<Integration> get(Integration entity);
// 
// 	public abstract Function<Integration, ? extends AbstractAuthResource> getToResourceMapper();
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public static Optional<AuthIntegrationType> fromId(String id) {
// 		return Arrays.stream(values()).filter(it -> it.name.equalsIgnoreCase(id)).findAny();
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return this.name;
// 	}
// }
// 
// Path: src/main/java/com/epam/reportportal/auth/integration/handler/CreateAuthIntegrationHandler.java
// public interface CreateAuthIntegrationHandler {
// 
// 	AbstractAuthResource createAuthIntegration(AuthIntegrationType type, UpdateAuthRQ request, ReportPortalUser user);
// 
// 	AbstractAuthResource updateAuthIntegration(AuthIntegrationType type, Long integrationId, UpdateAuthRQ request, ReportPortalUser user);
// 
// 	OAuthRegistrationResource createOrUpdateOauthSettings(String oauthProviderId, OAuthRegistrationResource clientRegistrationResource);
// }
// 
// Path: src/main/java/com/epam/reportportal/auth/integration/handler/DeleteAuthIntegrationHandler.java
// public interface DeleteAuthIntegrationHandler {
// 
// 	OperationCompletionRS deleteAuthIntegrationById(Long integrationId);
// 
// 	OperationCompletionRS deleteOauthSettingsById(String oauthProviderId);
// }
// 
// Path: src/main/java/com/epam/reportportal/auth/integration/handler/GetAuthIntegrationHandler.java
// public interface GetAuthIntegrationHandler {
// 
// 	AbstractAuthResource getIntegrationByType(AuthIntegrationType integrationType);
// 
// 	Map<String, OAuthRegistrationResource> getAllOauthIntegrations();
// 
// 	OAuthRegistrationResource getOauthIntegrationById(String oauthProviderId);
// }


// Path: src/main/java/com/epam/reportportal/auth/endpoint/AuthConfigurationEndpoint.java
import com.epam.reportportal.auth.integration.AuthIntegrationType;
import com.epam.reportportal.auth.integration.handler.CreateAuthIntegrationHandler;
import com.epam.reportportal.auth.integration.handler.DeleteAuthIntegrationHandler;
import com.epam.reportportal.auth.integration.handler.GetAuthIntegrationHandler;
import com.epam.ta.reportportal.commons.ReportPortalUser;
import com.epam.ta.reportportal.exception.ReportPortalException;
import com.epam.ta.reportportal.ws.model.ErrorType;
import com.epam.ta.reportportal.ws.model.OperationCompletionRS;
import com.epam.ta.reportportal.ws.model.integration.auth.AbstractAuthResource;
import com.epam.ta.reportportal.ws.model.integration.auth.UpdateAuthRQ;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.beans.PropertyEditorSupport;

	@PostMapping(value = "/{authType}")
	@ResponseStatus(HttpStatus.OK)
	@ApiOperation(value = "Create new auth integration")
	public AbstractAuthResource createAuthIntegration(@RequestBody @Valid UpdateAuthRQ request, @AuthenticationPrincipal ReportPortalUser user,
			@PathVariable AuthIntegrationType authType) {
		return createAuthIntegrationHandler.createAuthIntegration(authType, request, user);
	}

	/**
	 * Creates or updates auth integration settings
	 *
	 * @param request Update request
	 * @return Successful message or an error
	 */
	@Transactional
	@PutMapping(value = "/{authType}/{integrationId}")
	@ResponseStatus(HttpStatus.OK)
	@ApiOperation(value = "Update auth integration")
	public AbstractAuthResource updateAuthIntegration(@RequestBody @Valid UpdateAuthRQ request, @AuthenticationPrincipal ReportPortalUser user,
			@PathVariable AuthIntegrationType authType, @PathVariable Long integrationId) {
		return createAuthIntegrationHandler.updateAuthIntegration(authType, integrationId, request, user);
	}

	/**
	 * Get auth settings by type
	 *
	 * @param authType Type of Auth
	 * @return Successful message or an error
	 */
	@Transactional(readOnly = true)
	@GetMapping(value = "/{authType}")