---

connect_process_search_module: "{{ connect_search_elastic_enabled | ternary((connect_version is version('11.1', '>=') | ternary('external_v2', 'external')), 'embedded') }}"

connect_spring_profiles_include:
  - "{{ (true) | ternary('prod','') }}"
  - "{{ (true) | ternary('postgres','') }}"
  - "{{ connect_swagger_enabled | ternary('swagger','') }}"
  - "{{ (connect_process_search_module == 'external') | ternary('elastic','') }}"
  - "{{ (connect_process_search_module == 'external_v2') | ternary('cloudevents','') }}"
  - "{{ connect_ribbon_display | default('') }}"

connect_labels: [
  '"traefik.enable=true"',
  '"traefik.http.routers.{{ connect_id }}.service={{ connect_id }}"',
  '"traefik.http.routers.{{ connect_id }}.rule=Host(`{{ connect_base_url }}`)"',
  '"traefik.http.routers.{{ connect_id }}.entrypoints=websecure"',
  '"traefik.http.routers.{{ connect_id }}.tls=true"',
  '"traefik.http.routers.{{ connect_id }}.tls.certresolver=letsencrypt"',
  '"traefik.http.services.{{ connect_id }}.loadbalancer.server.port={{ service_port }}"',

  '"traefik.http.routers.{{ connect_id }}-admin.service={{ connect_id }}-admin"',
  '"traefik.http.routers.{{ connect_id }}-admin.rule=Host(`{{ connect_base_url }}`)"',
  '"traefik.http.routers.{{ connect_id }}-admin.entrypoints=admin-service"',
  '"traefik.http.routers.{{ connect_id }}-admin.tls=true"',
  '"traefik.http.routers.{{ connect_id }}-admin.tls.certresolver=letsencrypt"',
  '"traefik.http.services.{{ connect_id }}-admin.loadbalancer.server.port={{ management_port }}"',
]

connect_java_options_default:
  - "-Duser.country=DE"
  - "-Duser.language=de"

connect_java_options: []

connect_environment: [
  "TZ: \"{{ connect_time_zone | default('Europe/Berlin') }}\"",
  "NAME: \"{{ connect_name | default('Smardigo') }}\"",
  "TENANT_ID: \"{{ connect_client_id }}\"",
  "SMA_LANGUAGE_CODE: \"{{ connect_language_code | default('de') }}\"",

  "SMA_JWT_ENABLED: \"{{ connect_jwt_enabled | default('false') }}\"",
  "SMA_JWT_SECRET: \"{{ connect_jwt_secret | default('') }}\"",
  "SMA_CSRF_TOKEN_NAME: \"{{ connect_csrf_token_name | default('') }}\"",
  "SMA_CSRF_TOKEN_VALUE: \"{{ connect_csrf_token_value | default('') }}\"",
  "SPRING_PROFILES_INCLUDE: \"{{ connect_spring_profiles_include | select() | join(',') }}\"",

  "SMA_DEFAULT_THEME: \"{{ smardigo_default_theme }}\"",
  "RIBBON_DISPLAY_ON_ACTIVE_PROFILES: \"{{ connect_ribbon_display | default('') }}\"",

  "DATASOURCE_URL: \"jdbc:postgresql://{{ connect_postgres_host }}:{{ service_port_postgres }}/{{ connect_postgres_database }}?sslmode=require\"",
  "DATASOURCE_USERNAME: \"{{ connect_postgres_username }}\"",
  "DATASOURCE_PASSWORD: \"{{ connect_postgres_password }}\"",
  "FILE_WHITELIST_URL: \"{{ connect_whitelist_url | default('') }}\"",

  "MAIL_PROTOCOL: \"{{ connect_mail_protocol | default('smtp') }}\"",
  "MAIL_HOST: \"{{ connect_mail_host | default('smtp.tolina.local') }}\"",
  "MAIL_PORT: \"{{ connect_mail_port | default('25') }}\"",
  "MAIL_USER: \"{{ connect_mail_user | default('') }}\"",
  "MAIL_PASSWORD: \"{{ connect_mail_password | default('') }}\"",
  "MAIL_PROPERTIES_SIMULATION: \"{{ connect_mail_properties_simulation | default('true') }}\"",
  "MAIL_PROPERTIES_BASE_URL: \"{{ connect_mail_properties_base_url }}\"",
  "MAIL_PROPERTIES_BASE_URL_EXTERN: \"{{ connect_mail_properties_base_url_extern }}\"",
  "MAIL_PROPERTIES_SENDER: \"{{ connect_mail_properties_sender | default('noreply-connect@netgo.de') }}\"",
  "MAIL_PROPERTIES_SENDER_ALIAS: \"{{ connect_mail_properties_sender_alias | default('noreply-connect') }}\"",
  "MAIL_PROPERTIES_SMTP_AUTH: \"{{ connect_mail_properties_smtp_auth | default('false') }}\"",
  "MAIL_PROPERTIES_SMTP_STARTTLS_ENABLE: \"{{ connect_mail_properties_smtp_starttls_enable | default('false') }}\"",
  "MAIL_PROPERTIES_SMTP_STARTTLS_REQUIRED: \"{{ connect_mail_properties_smtp_starttls_required | default('false') }}\"",

  "AUTH_MODULE: \"{{ connect_auth_module | default('preauth') }}\"",
  "OIDC_CLIENT_ID: \"{{ connect_oidc_client_id | default('oidc_config_not_found') }}\"",
  "OIDC_CLIENT_SECRET: \"{{ connect_oidc_client_secret | default('oidc_config_not_found') }}\"",
  "OIDC_REGISTRATION_ID: \"{{ connect_oidc_registration_id | default('oidc_config_not_found') }}\"",
  "OIDC_ISSUER_URI: \"{{ connect_oidc_issuer_uri | default('oidc_config_not_found') }}\"",
  "PASSWORD_CHANGE_URL: \"{{ connect_password_change_url | default('') }}\"",
  "USER_MANAGEMENT_URL: \"{{ connect_user_management_url | default('') }}\"",

  "IAM_MODULE: \"{{ connect_iam_module | default('embedded') }}\"",
  "IAM_CLIENT_ENABLED: \"{{ smardigo_iam_client_enabled | default('false') }}\"",
  "EXTERNAL_IAM_SERVER_URL: \"{{ smardigo_iam_client_server_url | default('') }}\"",

  "PROCESS_SEARCH_MODULE: \"{{ connect_process_search_module }}\"",
  "PROCESS_SEARCH_BASE_PATH: \"http://{{ process_search_id }}:{{ service_port }}\"",

  "ELASTIC_HOST: \"{{ connect_elastic_host | default('') }}\"",
  "ELASTIC_PREFIX: \"{{ connect_elastic_prefix | replace('-','_') }}\"",
  "ELASTIC_USERNAME: \"{{ connect_elastic_username | default('') }}\"",
  "ELASTIC_PASSWORD: \"{{ connect_elastic_password | default('') }}\"",
  "ELASTIC_CA: \"{{ connect_elastic_ca | default('') }}\"",
  "ELASTIC_SEARCH_INDEX: \"{{ connect_elastic_search_index | default('search') }}\"",
  "ELASTIC_MESSAGE_INDEX: \"{{ connect_elastic_message_index | default('message') }}\"",
  "ELASTIC_ANALYSIS_INDEX: \"{{ connect_elastic_analysis_index | default('analysis') }}\"",

  "WORKFLOW_ENV: \"{{ (connect_workflow_env | default([])) | join(';') }}\"",

  "CONFIG_DELETE_SCOPE_ENABLED: \"{{ connect_config_delete_scope_enabled }}\"",
  "CONFIG_LOCAL_IMPORT_ENABLED: \"{{ connect_config_local_import_enabled }}\"",
  "DATASOURCE_ACTION_ENABLED: \"{{ connect_datasource_action_enabled }}\"",
  "ELEMENT_TEMPLATE_ENABLED: \"{{ connect_element_template_enabled }}\"",
  "EXTERNAL_TASK_SCRIPT_WORKER_ENABLED: \"{{ connect_external_task_script_worker_enabled }}\"",
  "RESUBMISSION_ENABLED: \"{{ connect_resubmission_enabled }}\"",
  "SMA_WORKFLOW_HEATMAP_ENABLED: \"{{ connect_workflow_heatmap_enabled }}\"",

  "SPRINGDOC_SERVER_URL: \"{{ http_s }}://{{ connect_base_url }}\"",

  "SMA_CORS_ORIGINS: \"{{ http_s }}://{{ connect_base_url }}:{{ admin_port_service }}\"",
  "SMA_CORS_ALLOWED_METHODS: \"*\"",
  "SMA_CORS_ALLOWED_HEADERS: \"*\"",
  "SMA_CORS_PATH_PATTERN: \"/**\"",

  "LOG_LEVEL_CAMUNDA: \"{{ connect_loglevel_camunda | default('OFF') }}\"",
  "LOG_LEVEL_JASYPT: \"{{ connect_loglevel_jasypt | default('ERROR') }}\"",
  "LOG_LEVEL_MESSAGE_QUEUE: \"{{ connect_loglevel_message_queue | default('INFO') }}\"",
  "LOG_LEVEL_DOCUMENT_INDEX: \"{{ connect_loglevel_document_index | default('INFO') }}\"",
  "LOG_LEVEL_WORKFLOW_INDEX: \"{{ connect_loglevel_workflow_index | default('INFO') }}\"",
  "LOG_LEVEL_WORKFLOW_ANALYSIS: \"{{ connect_loglevel_workflow_analysis | default('INFO') }}\"",

  "OPENTRACING_JAEGER_ENABLED: \"{{ connect_opentracing_jaeger_enabled | default('false') }}\"",
  "OPENTRACING_JAEGER_LOG_SPANS: \"{{ connect_opentracing_jaeger_log_spans | default('false') }}\"",
  "OPENTRACING_JAEGER_SERVICE_NAME: \"{{ connect_opentracing_jaeger_service_name | default(connect_id) }}\"",
  "OPENTRACING_JAEGER_HTTP_SENDER_URL: \"{{ connect_opentracing_jaeger_http_sender_url | default() }}\"",

  "JDK_JAVA_OPTIONS: \"{{ ( connect_java_options + connect_java_options_default ) | join(' ') }}\"",

  "SMA_CUSTOM_SCRIPTING_WHITELIST_FILE: \"/usr/share/smardigo/custom-whitelist\"",
]

process_search_labels: []

process_search_environment: [
  "TZ: \"{{ connect_time_zone | default('Europe/Berlin') }}\"",
  "KNATIVE_BROKER_URL: \"http://{{ connect_id }}:{{ service_port }}\"",

  "IAM_URL: \"{{ smardigo_iam_client_server_url | default('') }}\"",
  "IAM_API_KEY_VALUE: \"{{ iam_auth_token_value }}\"",
  "IAM_LEGACY: \"true\"",
  "IAM_LEGACY_USER_PERMISSION_URL: \"http://{{ connect_id }}:{{ service_port }}\"",
  "IAM_LEGACY_USER_PERMISSION_API_KEY_VALUE: \"{{ smardigo_auth_token_value }}\"",

  "RUNTIME_CONFIG_URL: \"http://{{ connect_id }}:{{ service_port }}\"",
  "RUNTIME_CONFIG_LEGACY: \"true\"",
  "RUNTIME_CONFIG_API_KEY_VALUE: \"{{ smardigo_auth_token_value }}\"",

  "PROCESS_PERSISTENCE_URL: \"http://{{ connect_id }}:{{ service_port }}\"",
  "PROCESS_PERSISTENCE_LEGACY: \"true\"",
  "PROCESS_PERSISTENCE_API_KEY_VALUE: \"{{ smardigo_auth_token_value }}\"",

  "PROCESS_ACCESS_URL: \"http://{{ connect_id }}:{{ service_port }}\"",
  "PROCESS_ACCESS_LEGACY: \"true\"",
  "PROCESS_ACCESS_API_KEY_VALUE: \"{{ smardigo_auth_token_value }}\"",

  "PROCESS_RESUBMISSION_URL: \"http://{{ connect_id }}:{{ service_port }}\"",
  "PROCESS_RESUBMISSION_LEGACY: \"true\"",
  "PROCESS_RESUBMISSION_API_KEY_VALUE: \"{{ smardigo_auth_token_value }}\"",

  "PROCESS_TWO_PERSON_RULE_URL: \"http://{{ connect_id }}:{{ service_port }}\"",
  "PROCESS_TWO_PERSON_RULE_API_KEY_VALUE: \"{{ smardigo_auth_token_value }}\"",

  "DATASOURCE_URL: \"{{ process_search_postgres_host }}:{{ service_port_postgres }}/{{ process_search_postgres_database }}?sslmode=require\"",
  "DATASOURCE_USERNAME: \"{{ process_search_postgres_username }}\"",
  "DATASOURCE_PASSWORD: \"{{ process_search_postgres_password }}\"",
  "FLYWAY_ENABLED: \"true\"",

  "OS_PROTOCOL: \"{{ connect_elastic_protocol | default('https') }}\"",
  "OS_HOSTS: \"{{ connect_elastic_host | default('') }}:{{ service_port_elasticsearch }}\"",
  "OS_USERNAME: \"{{ connect_elastic_username | default('') }}\"",
  "OS_PASSWORD: \"{{ connect_elastic_password | default('') }}\"",
  "OS_CERTS_URI: \"{{ connect_elastic_ca | default('') }}\"",
  # "OS_LOG_LEVEL: \"DEBUG\""
  "INDEX_PREFIX: \"{{ connect_elastic_prefix | replace('-','_') }}-{{ connect_elastic_search_index | default('search') }}\"",
  "QUARKUS_PROFILE: \"elastic\"",
  "QUARKUS_REBUILD: \"true\"",
]

connect_docker: {
  networks: [
    {
      name: back-tier,
      external: true,
    },
    {
      name: front-tier,
      external: true,
    },
  ],
  services: [
    {
      name: "{{ connect_id }}",
      image_name: "{{ connect_image_name }}",
      image_version: "{{ connect_version }}",
      labels: "{{ connect_labels + ( connect_labels_additional | default([])) }}",
      restart: "{{ connect_service_restart | default('always') }}",
      environment: "{{ connect_environment + ( connect_environment_additional | default([])) }}",
      volumes: [
        '"./certs/ca/ca.crt:/usr/share/smardigo/ca.crt:ro"',
        '"./config/custom-whitelist:/usr/share/smardigo/custom-whitelist:ro"',
        "./config/application-cloudevents.yml:/config/application-cloudevents.yml:ro"
      ],
      networks: [
        '"back-tier"',
        '"front-tier"',
      ],
      extra_hosts: "{{ connect_extra_hosts | default([]) }}",
    },
    {
      active: "{{ connect_process_search_module == 'external_v2' }}",
      name: "{{ process_search_id }}",
      image_name: "{{ process_search_image_name }}",
      image_version: "{{ process_search_version }}",
      labels: "{{ process_search_labels + ( process_search_labels_additional | default([])) }}",
      restart: "{{ process_search_service_restart | default('always') }}",
      environment: "{{ process_search_environment + ( process_search_environment_additional | default([])) }}",
      volumes: [
        '"./certs/ca/ca.crt:/usr/share/smardigo/ca.crt:ro"',
      ],
      networks: [
        '"back-tier"',
      ],
    }
  ],
}
