package uk.ltd.scimitar.heartspark.server.security.config;

import org.keycloak.admin.client.Keycloak;
import org.keycloak.admin.client.KeycloakBuilder;
import org.wildfly.swarm.spi.runtime.annotations.ConfigurationValue;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;

@ApplicationScoped
public class SSOAdminConfig {

    @Inject
    @ConfigurationValue("heartspark.sso.url")
    private String keycloakUrl;

    @Inject
    @ConfigurationValue("heartspark.sso.admin.username")
    private String username;

    @Inject
    @ConfigurationValue("heartspark.sso.admin.password")
    private String password;

    @Inject
    @ConfigurationValue("heartspark.sso.client.secret")
    private String clientSecret;

    @Produces
    public Keycloak keycloakClient() {
        return KeycloakBuilder.builder()
                .realm("HeartSpark")
                .clientId("web.heartspark.singles")
                .serverUrl(keycloakUrl)
                .username(username)
                .password(password)
                .clientSecret(clientSecret)
                .build();
    }

}
