include "application"

# Used to encrypt JWT token and HTTP session state (cookie)
play.http.secret.key = ${DATAINTEGRATION_PLAY_HTTP_SECRET}

# sets "secure" flag in PLAY_SESSION cookie
# https://www.playframework.com/documentation/2.8.x/SettingsSession
play.http.session.secure = ${DATAINTEGRATION_SECURE_COOKIE}

# Used to encrypt password parameter values inside DI plugin tasks (e.g. send notification email)
plugin.parameters.password.crypt.key = ${DATAINTEGRATION_PASSWORD_CRYPT_KEY}

# The OAuth client that will be used to load the workspace initially and run the schedulers.
# In order to enable that feature, you have to enable the service account feature in the Keycloak
# OIDC client "cmem-service-client". Furthermore, an AccessCondition that maps with `eccauth:requiresClient :cmem-service-account`
# is required.
workbench.superuser.client = ${?DATAINTEGRATION_CMEM_SERVICE_CLIENT}
workbench.superuser.clientSecret = ${?DATAINTEGRATION_CMEM_SERVICE_CLIENT_SECRET}

# timeouts
play.server.akka.requestTimeout = ${SERVER_REQUEST_TIMEOUT}
play.server.http.idleTimeout = ${SERVER_IDLE_TIMEOUT}

# Server port
play.server.http.port = ${SERVER_PORT}

#################################################
# Play specific settings
#################################################

# The secret used for cryptography.
# NOTE: this has no effect in this config file and must be set in the production.conf! Only here for documentation purposes.
# play.crypto.secret = "doesn't matter here, read NOTE"

# The application loader
play.application.loader = "EccencaApplicationLoader"

# set application context
play.http.context= ${SERVER_CONTEXTPATH}

# Set public host of DI. Necessary for generating redirect URLs and artifact URLs of the new DI React frontend.
workbench.host = ${DEPLOY_HOSTNAME}

# Define the protocol used for accessing the workbench (http or https), defaults to http
workbench.protocol = ${DEPLOY_PROTOCOL}

# set application max upload file size
play.http.parser.maxDiskBuffer = ${MAX_UPLOAD_FILE_SIZE}


#################################################
# SearchKit integration
#################################################
search.elasticsearch.baseUrl = "http://elasticsearch:9200"


#################################################
# eccenca DataManager
#################################################
# The base URL of the DataManager. Used for linking data manager resources.
eccencaDataManager.baseUrl = ${EXPLORE_FRONTEND_URL}

# Links to DM modules. Each entry is composed of the path relative to the DM base URL (see eccencaDataManager.baseUrl)
# and the default label. The labels will also be configured in the language files. The icon entry is technical optional
# but it should be defined to support the main navigation.
# Default order is vocabs, explore, query -- please uncomment this section if you want reduce, extend or reorder.
#eccencaDataManager.moduleLinks = [
#  {
#    path = "vocab"
#    defaultLabel = "Vocabulary Management"
#    icon = "application-vocabularies"
#  },
#  {
#    path = "explore"
#    defaultLabel = "Exploration"
#    icon = "application-explore"
#  },
#  {
#    path = "query"
#    defaultLabel = "Queries"
#    icon = "application-queries"
#  }
#]


#################################################
# eccenca explore
#################################################

# The configuration for the eccenca DataPlatform connection
eccencaDataPlatform.url = ${EXPLORE_BACKEND_URL}
eccencaDataPlatform.endpointId = "default"
eccencaDataPlatform.health.waitingTimeInSeconds = 240
eccencaDataPlatform.oauth = true
eccencaDataPlatform.writeGraphType = true

oauth.clientId = ${OAUTH_CLIENT_ID}
oauth.authorizationUrl = ${OAUTH_AUTHORIZATION_URL}
oauth.tokenUrl = ${OAUTH_TOKEN_URL}
oauth.endSessionUrl = ${OAUTH_LOGOUT_URL}
oauth.logoutRedirectUrl = ${OAUTH_LOGOUT_REDIRECT_URL}

oauth.idToken = true
oauth.offlineToken=true
user.manager.web.plugin = "oauthUserManager"


#################################################
# Workspace
#################################################

# Set the used workspace
workspace.provider.plugin = backend

# Resource Repositories (see https://documentation.eccenca.com/latest/deploy-and-configure/configuration/dataintegration/?h=resource+repo#resource-repositories)
workspace.repository.plugin = {{ .Values.dataintegration.config.workspaceRepository.plugin }}
workspace.repository.{{ .Values.dataintegration.config.workspaceRepository.plugin }} = {
{{- if eq .Values.dataintegration.config.workspaceRepository.plugin "projectFile" "sharedFileRepository" }}
    dir = "{{ .Values.dataintegration.config.datalakeFolder }}"
{{- else if eq .Values.dataintegration.config.workspaceRepository.plugin "projectS3" "s3" }}
    bucket = {{ .Values.dataintegration.config.workspaceRepository.s3.bucket | quote | required ".Values.dataintegration.config.workspaceRepository.s3.bucket is required."}}
    {{- if .Values.dataintegration.config.workspaceRepository.s3.accessKeyId }}
    accessKeyId = ${DATAINTEGRATION_WORKSPACEREPO_S3_ACCESSKEY}
    {{- else }}
    accessKeyId = ""
    {{- end }}
    {{- if .Values.dataintegration.config.workspaceRepository.s3.secretKey }}
    secretKey = ${DATAINTEGRATION_WORKSPACEREPO_S3_SECRETKEY}
    {{- else }}
    secretKey = ""
    {{- end }}
    region = {{ .Values.dataintegration.config.workspaceRepository.s3.region | quote | required ".Values.dataintegration.config.workspaceRepository.s3.region is required."}}
    {{- if .Values.dataintegration.config.workspaceRepository.s3.path }}
    path = {{ .Values.dataintegration.config.workspaceRepository.s3.path | quote }}
    {{- end }}
{{- end }}
}

# Workspace on the RDF store (requires backend.url parameter to be defined)
workspace.provider.backend = {
dir = "{{ .Values.dataintegration.config.home }}/" # Optional: File system path for holding resources, such as input datasets
}

execution.manager.plugin = ${DATAINTEGRATION_EXECUTOR}


#################################################
# Execution Report Manager
#################################################

# see https://documentation.eccenca.com/latest/deploy-and-configure/configuration/dataintegration/#execution-report-manager
workspace.reportManager.plugin = {{ .Values.dataintegration.config.executionReportManager.plugin }}

{{- if eq .Values.dataintegration.config.executionReportManager.plugin "fileExecutionReportManager" }}
workspace.reportManager.fileExecutionReportManager = {
dir = "{{ .Values.dataintegration.config.executionReportManager.folder }}"
retentionTime = "{{ .Values.dataintegration.config.executionReportManager.retentionTime }}"
}
{{- else if eq .Values.dataintegration.config.executionReportManager.plugin "inMemoryExecutionReportManager " }}
workspace.reportManager.inMemory = {
retentionTime = "{{ .Values.dataintegration.config.executionReportManager.retentionTime }}"
}
{{- end }}

#################################################
# Internal Dataset
#################################################

dataset.internal.plugin = inMemory
# dataset.internal.plugin = eccencaDataPlatform
# dataset.internal.plugin = sparqlEndpoint

dataset.internal.eccencaDataPlatform = {
graph = "https://ns.eccenca.com/dataintegration/internal"
}


#################################################
# Vocabulary Manager
#################################################

# Reads vocabularies from specific graphs of the workspace RDF backend. Vocabularies are referenced by graph URI.
# In addition to the 'rdf' plugin the 'dpVocabManager' plugin is also able to get a list of currently installed vocabularies from the EXPLORE.
vocabulary.manager.plugin = dpVocabManager


#################################################
# Provenance
#################################################

user.manager.web.plugin=oauthUserManager
provenance.persistWorkflowProvenancePlugin.plugin=nopWorkflowProvenance

# Provenance can be enabled by uncommenting the following lines
# provenance.graph = https://ns.eccenca.com/provenance/
# provenance.persistWorkflowProvenancePlugin.plugin=rdfWorkflowProvenance

###############################################
### Runtime
###############################################

# Files larger than this limit are not loaded into memory (e.g., when reading JSON). If not set, the default will be used
# org.silkframework.runtime.resource.Resource.maxInMemorySize = 100MB

#################################################
# Spark
#################################################
spark.interpreter.options = {
# URL of the Spark cluster master node, optional, default is local[1]
sparkMaster = "local[4]"
# The IP of the driver programms machine in client-mode, required for client and cluster modes
sparkLocalIP = "localhost"
# jars containing the spark code, local file will be copied to the cluster, required for client mode
sparkJars = ""
#sparkJars = "/opt/cmem/eccenca-DataIntegration/dist/etc/dataintegration/plugin/eccenca-DataIntegration-assembly.jar"
# Specifies local, client-mode or full cluster-mode deployment, required: local,client or cluster
deploymentMode = "local"
# Folder for intermediate results, optional, default: /tmp
temporaryFolder = "/tmp/"
# Specifies the folder for event and time log, optional, default: /tmp
logFolder = "{{ .Values.dataintegration.cache.cacheBasePath }}/logs"
# Persists intermediate results from all phases (DataSet load/store, Transform, Linking) if true
materializeIntermediateResults = false
# Persists all data sets in Hive if true (concurrently to saving them in the specified data set)
materializeInHive = false
# Enables more detailed logging, counting of transformed records, etc.
debugMode = false
# Enables the use of certain testing implementations for non-integration tests (e.g. HiveTestContext instead of HiveContext)
testMode = false
# Enable or disable a spark executor event log for debugging purposes
eventLog = true
# Enable or disable an execution time log for benchmarking purposes
timeLog = false
# Enable or disable Sparks built-in log for debugging purposes
sparkLog = true
# If true, data will be repartitioned before execution, otherwise the existing partitioning or no partitioning will be used
partitionOnImport = false
# Number of partitions for repartitioning on Import (for local filesystems and local execution modes a low number is recommended)
partitionNumber = 4
# Attribute used for Repartioning
partitionKey = "URI"
# Specifies number of Spark SQL shuffle partitions
shufflePartitions = 16
# Minimum partition number for Spark execution
defaultMinPartitions = 4
# Default parallelism partition number for Spark execution
defaultParallelism = 4
# Specifies if data is combined before output is written to disk. If true the final output will be in a single file on a single partition
# This needs to be true when working with resources on the local filesystem (e.g. when csv file is used a target dataset of a workflow)
combineOutput = true
# Internal data model used in Spark Data Frames: 'sequence' or 'simple'. Sequence behaves like the entities used by the local executor of DataIntegration and is
# sometimes be needed to work with non relational data (i.e. triple stores, explore). The default value is 'simple' and casts most data objects to Strings
# which is fast and works in most situations.
columnType = sequence
}


#################################################
# Spark SQL options
#################################################

spark.sql.options {
# The username of a user that can access all tables and views shared via the SQL Endpoint dataset
endpointUser = "admin"
# Password for authentification of the SQL Endpoint dataset user
endpointPassword = "admin"
# When SparkSQL wit Hive integration is needed, it can be configured with enableHiveSuport = true. If true the Hive metastore
# facilities are used by SparkSQL as well.
# This is influence mainly Spark SQL (i.e. the SqlEndpoint datasets) but also can have impact on avro, orc, parquet
# Be aware that the internal metastore (which is Derby for testing) of Hive is not supported in production environments.
# To use hive an external DB (such as MYSQL) is needed. See also hive-site.xml, spark-defaults.conf for more hive related
# settings.
enableHiveSupport = false
# Specifies if DataIntegration is allowed to start a thrift server for external JDBC access.
# Views on relational data (SqlEndpoint datasets) can still be used in workflows (read and written to similar to a file).
# By default, external access to views via JDBC should be disabled.
# Note: If set to true security settings in hive-site.xml need to be specified. Warnings in the log will give hints regarding the configuration.
startThriftServer = true
{{- if .Values.dataintegration.config.sparksqloption }}
{{ .Values.dataintegration.config.sparksqloption }}
{{- end }}
}

#################################################
# Spark deployment options
#################################################

spark.deployment.options = {
# Specifies artifacts: jar, project, projet-jar. Deploys the assembly jar, a project zip or both
artifact = "project-jar"
# A deployment type (copy, hdfs, script) can be specified for each phase (staging, transform, loading).
staging.type = "script"
# Deployment target: A destination folder, hdfs directory (starting with hdfs://), a script location depending on the type
staging.script = "./conf/deployment-scripts/uploadWorkflow.sh"
# Another example: copy project and jar to /tmp (and /data)
loading.type = "copy"
loading.copy = "/tmp,"${DATA_HOME}
# A script from an environment variable named ECC_DEPLOYMENT_SCRIPT can be executed as can a script from this config
# staging.type = "env-script"
# staging.type = "var-script"
# staging.var-script = ""
# Specifies if the deployment action should run on pressing 'ExecuteSparkWorkflow', default = false
overwriteExecution = true
}


###############################################
# External matching project
###############################################

# The external matching project in the workspace containing the matching link spec
matching.external.projectId = "matchingProject"
# The link spec in the matching project that should be executed on the source and target ontology
matching.external.linkSpecId = "matchingLinkSpec"


#################################################
# Logging
#################################################

# Logging Configuration
logger.root=DEBUG
logger.play=INFO
logger.application=DEBUG

# Log all REST requests
logging.level.oauth.OAuthWebUserManager=DEBUG

#################################################
# Plugin Configuration
# see system manual for details
#################################################
{{- if .Values.dataintegration.config.pythonPluginConf.enabled }}
# this (optional) file can be used to hold python plugin specific configuration
include "python-plugins.conf"
{{- end }}
# pluginRegistry {
  # External plugins are loaded from this folder
  # pluginFolder = "{{ .Values.dataintegration.config.pluginFolder }}"
  # Configuration of individual plugins.
  # plugins {
    # Plugins can be enabled/disabled here by setting {pluginId}.enabled
    ## Enable Python transform operator, which is disabled by default for security reasons.
    # python2Script.enabled = true
    ## Enable Scala transform operator, which is disabled by default for security reasons.
    # scalaScript.enabled = true
    ## Enable Workflow operator script operator, which is disabled by default for security reasons.
    # script.enabled = true
    ## Enable outdated Spotlight transform operator
    # spotlight.enabled = true
    ## Enable geo location type discoverer
    # GeoLocationTypeDiscoverer.enabled = true
  # }
# }

# plugin.blacklist = "script" # This will blacklist the Script Task
# Disable geo location type discoverer by default. See CMEM-2993. If you want to disable other type discovers as well, add them as comma-separated list:
#   DateTypeDiscoverer,GeoCoordinateTypeDiscoverer,IsinTypeDiscoverer,NumericTypeDiscoverer,SkosCurrencyTypeDiscoverer,SkosGicsSectorTypeDiscoverer,SkosGicsIndustryTypeDiscoverer,SkosGicsIndustryGroupTypeDiscoverer
plugin.blacklist = "GeoLocationTypeDiscoverer"

pluginRegistry.pluginFolder = ${DATAINTEGRATION_PLUGIN_FOLDER}

com.eccenca.di.scripting = {
  python = {
    PythonPluginRegistry = {
      # Python plugins will only be loaded if 'enabled' is set to true.
      enabled = true

      # Plugins will only be loaded below the following base package.
      basePackage = "cmem"
    }

    PythonPackageManager = {
      # Python package installer executable.
      # pipExecutable = "pip"
      pipExecutable = "cmem-pip-wrapper.sh"
    }
  }
}

###############################################
### Global Variables
###############################################

config.variables = {

  # Template engine
  # Can be disabled by setting: engine = "disabled"
  engine = "jinja"

  global = {
    # Insert global variables here
    # myVar = "value"
    {{- range $k, $v := .Values.dataintegration.config.globalVariables }}
    {{ $k }} = {{ $v | quote }}
    {{- end }}
  }

}

###############################################
### Caches
###############################################

# Max number of links that are cached, default is 50. This limit is per forward and backward paths, i.e. the max number of links can be twice the number.
caches.linkingPathCache.maxLinks = {{ .Values.dataintegration.cache.maxLinks }}

# Load caches automatically, e.g. after DI start up, task creation/update
# caches.config.enableAutoRun=true

# Persistent cache directory. Directory used to store (some) persistent caches.
# caches.persistence.directory=${elds.home}"/var/dataintegration/caches/"
# caches.persistence.maxSize=10GB
caches.config.enableAutoRun=true
caches.persistence.directory="{{ .Values.dataintegration.cache.cacheBasePath }}/caches/"
# this B in the end is mandatory
caches.persistence.maxSize= {{ .Values.dataintegration.cache.cacheSize }}


###############################################
### Workspace
###############################################
# Enables the workspace switch to allow to switch to the workspace beta version
workspace.beta.switch.enabled=true

# The favicon. Must either be a data URI or point to a file in the conf directory. At the moment, only PNG is supported.
# Note that the conf directory is not forwarded to the container by default, so if you specify a file you have to mount it.
# workbench.logoSmall = "data:image/png;base64,..."
{{- if .Values.dataintegration.config.workbenchFavIcon }}
workbench.logoSmall = {{ .Values.dataintegration.config.workbenchFavIcon | quote }}
{{- end }}

###############################################
### Metrics config (probably enabled in dataintegration v24.3)
###############################################
# Port of the HTTP endpoint for exposing polling metrics (e.g. for Prometheus)
metrics.endpoint.port = 9100

# Enable exposing Micrometer metrics. The specific monitoring system (such as Prometheus) is an implementation detail.
metrics.enabled = {{ .Values.explore.config.metrics.enabled | quote }}

# Prefix for the Micrometer metrics.
metrics.prefix = "cmem"

# Application name for the Micrometer metrics.
metrics.app = "build"

###############################################
### Mapping Creator
###############################################


# Enable Mapping Creator
com.eccenca.di.mappingCreatorEnabled = {{ .Values.dataintegration.config.mappingCreator.enabled }}

{{- if .Values.dataintegration.config.mappingCreator.enabled }}
# LLM config. Might be changed in the future.
com.eccenca.di.assistant = {
  ApiConfig = {
    useDataPlatformGateway = ${DATAINTEGRATION_AI_USE_EXPLORE_GATEWAY}
    {{- if not .Values.dataintegration.config.mappingCreator.useDataPlatformGateway }}
    # API key
    apiKey = ${DATAINTEGRATION_AI_APIKEY}

    # Optional organisation id for OpenAI accounts
    orgId = ${DATAINTEGRATION_AI_ORGID}

    # Model to use for mapping suggestions
    # model = "gpt-5-mini"
    model = ${DATAINTEGRATION_AI_MODEL}

    # URL of OpenAI-compatible endpoint, leave empty for official OpenAI API
    # coreUrl = "https://openrouter.ai/api/v1"
    coreUrl = ${DATAINTEGRATION_AI_COREURL}

    # Controls how many reasoning tokens the model generates before producing a response.
    # One of "low", "medium, "high". Set to null for default.
    # reasoningEffort = null
    reasoningEffort = ${DATAINTEGRATION_AI_REASONINGEFFORT}

    # Extra parameters to be passed to the API
    # extraParameters = {
    #   provider = {
    #     require_parameters: true
    #   }
    # }
    {{- end }}
    # Log prompts and responses
    # logQueries = true
    logQueries = ${DATAINTEGRATION_AI_LOGQUERIES}
  }
}
{{- end }}

{{- if .Values.dataintegration.config.additionalCustomConfig }}
###############################################
### Additional Custom Configuration
###############################################
{{ .Values.dataintegration.config.additionalCustomConfig }}
{{- end }}