class EnvironmentBasedDomainNameProvider {

    public String getDomainName(String environmentName, String accountName) {
        if (StringUtils.isEmpty(environmentName)) {
            LOGGER.error("The required parameters hasn't been specified, environment name: {}, account name: {}", environmentName, accountName);
            throw new IllegalStateException(ENV_NAME_SHOULD_BE_SPECIFIED_MSG);
        }

        if (StringUtils.isEmpty(accountName)) {
            LOGGER.error("The required parameters hasn't been specified, environment name: {}, account name: {}", environmentName, accountName);
            throw new IllegalStateException(String.format(ACCOUNT_NAME_IS_EMTPY_FORMAT, environmentName));
        }

        LOGGER.info("Generating domain with environment name: '{}', account name: '{}' and root domain: '{}'", environmentName, accountName, rootDomain);
        StringBuilder sb = new StringBuilder()
                .append(truncateEnvironment(environmentName))
                .append(DOMAIN_PART_DELIMITER)
                .append(accountName);

        if (!rootDomain.startsWith(DOMAIN_PART_DELIMITER)) {
            sb = sb.append(DOMAIN_PART_DELIMITER);
        }
        String result = sb.append(rootDomain).toString();
        validateDomainPattern(result);
        LOGGER.info("Generated domain: '{}'", result);
        return result;
    }

}