{{- /*
SkillHub 应用 ConfigMap
*/}}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "skillhub.fullname" . }}-config
  labels:
    {{- include "skillhub.labels" . | nindent 4 }}
data:
  # Redis 配置
  redis-host: {{ include "skillhub.redis.host" . | quote }}
  redis-port: {{ include "skillhub.redis.port" . | quote }}

  # 存储路径
  storage-base-path: "/var/lib/skillhub/storage"

  # 存储提供者: local | s3
  skillhub-storage-provider: {{ if .Values.s3.enabled }}"s3"{{ else }}"local"{{ end }}

  {{- if .Values.s3.enabled }}
  # S3 配置
  s3-bucket: {{ .Values.s3.bucket | quote }}
  s3-endpoint: {{ .Values.s3.endpoint | quote }}
  s3-public-endpoint: {{ .Values.s3.publicEndpoint | quote }}
  s3-region: {{ .Values.s3.region | quote }}
  s3-force-path-style: {{ .Values.s3.forcePathStyle | quote }}
  s3-disable-chunked-encoding: {{ .Values.s3.disableChunkedEncoding | quote }}
  s3-auto-create-bucket: {{ .Values.s3.autoCreateBucket | quote }}
  s3-presign-expiry: {{ .Values.s3.presignExpiry | quote }}
  {{- end }}

  # 技能扫描器
  skill-scanner-enabled: {{ .Values.scanner.enabled | quote }}
  skill-scanner-url: {{ printf "http://%s-scanner:%v" (include "skillhub.fullname" .) .Values.scanner.service.port | quote }}
  skill-scanner-mode: "upload"

  # Bootstrap 管理员
  bootstrap-admin-enabled: {{ .Values.bootstrapAdmin.enabled | quote }}
  bootstrap-admin-user-id: {{ .Values.bootstrapAdmin.userId | quote }}
  bootstrap-admin-username: {{ .Values.bootstrapAdmin.username | quote }}
  bootstrap-admin-display-name: {{ .Values.bootstrapAdmin.displayName | quote }}
  bootstrap-admin-email: {{ .Values.bootstrapAdmin.email | quote }}

  # Session
  session-cookie-secure: {{ or .Values.session.cookieSecure (not (empty .Values.ingress.tls)) .Values.ingress.certManager.enabled | quote }}
  session-redis-namespace: {{ .Values.session.redisNamespace | quote }}
  session-repository-type: {{ .Values.session.repositoryType | quote }}
  session-redis-configure-action: {{ .Values.session.configureAction | quote }}
  auth-account-merge-enabled: {{ .Values.auth.accountMerge.enabled | quote }}
  auth-account-merge-session-cutover-complete: {{ .Values.auth.accountMerge.sessionCutoverComplete | quote }}

  # Public URL and authentication
  public-base-url: {{ .Values.publicBaseUrl | quote }}
  {{- $deviceAuthVerificationUri := .Values.deviceAuthVerificationUri }}
  {{- if and (not $deviceAuthVerificationUri) .Values.publicBaseUrl }}
  {{- $deviceAuthVerificationUri = printf "%s/cli/auth" (trimSuffix "/" .Values.publicBaseUrl) }}
  {{- end }}
  device-auth-verification-uri: {{ $deviceAuthVerificationUri | quote }}
  auth-direct-enabled: {{ .Values.auth.direct.enabled | quote }}
  auth-direct-provider: {{ .Values.auth.direct.provider | quote }}
  auth-ldap-enabled: {{ .Values.auth.ldap.enabled | quote }}
  auth-ldap-provider-code: {{ .Values.auth.ldap.providerCode | quote }}
  auth-ldap-display-name: {{ .Values.auth.ldap.displayName | quote }}
  auth-ldap-authority: {{ .Values.auth.ldap.authority | quote }}
  auth-ldap-url: {{ .Values.auth.ldap.url | quote }}
  auth-ldap-start-tls: {{ .Values.auth.ldap.startTls | quote }}
  auth-ldap-directory-type: {{ .Values.auth.ldap.directoryType | quote }}
  auth-ldap-base-dn: {{ .Values.auth.ldap.baseDn | quote }}
  auth-ldap-user-search-base: {{ .Values.auth.ldap.userSearchBase | quote }}
  auth-ldap-user-search-filter: {{ .Values.auth.ldap.userSearchFilter | quote }}
  auth-ldap-bind-dn: {{ .Values.auth.ldap.bindDn | quote }}
  auth-ldap-subject-attribute: {{ .Values.auth.ldap.subjectAttribute | quote }}
  auth-ldap-subject-type: {{ .Values.auth.ldap.subjectType | quote }}
  auth-ldap-username-attribute: {{ .Values.auth.ldap.usernameAttribute | quote }}
  auth-ldap-display-name-attribute: {{ .Values.auth.ldap.displayNameAttribute | quote }}
  auth-ldap-email-attribute: {{ .Values.auth.ldap.emailAttribute | quote }}
  auth-ldap-avatar-url-attribute: {{ .Values.auth.ldap.avatarUrlAttribute | quote }}
  auth-ldap-email-authoritative: {{ .Values.auth.ldap.emailAuthoritative | quote }}
  auth-ldap-connect-timeout: {{ .Values.auth.ldap.connectTimeout | quote }}
  auth-ldap-read-timeout: {{ .Values.auth.ldap.readTimeout | quote }}
  auth-ldap-pool-wait-timeout: {{ .Values.auth.ldap.poolWaitTimeout | quote }}
  auth-ldap-max-concurrent-requests: {{ .Values.auth.ldap.maxConcurrentRequests | quote }}
  auth-ldap-max-attribute-values: {{ .Values.auth.ldap.maxAttributeValues | quote }}
  auth-cas-enabled: {{ .Values.auth.cas.enabled | quote }}
  auth-cas-provider-code: {{ .Values.auth.cas.providerCode | quote }}
  auth-cas-display-name: {{ .Values.auth.cas.displayName | quote }}
  auth-cas-authority: {{ .Values.auth.cas.authority | quote }}
  auth-cas-server-url: {{ .Values.auth.cas.serverUrl | quote }}
  auth-cas-service-url: {{ .Values.auth.cas.serviceUrl | quote }}
  auth-cas-protocol-version: {{ .Values.auth.cas.protocolVersion | quote }}
  auth-cas-subject-type: {{ .Values.auth.cas.subjectType | quote }}
  auth-cas-connect-timeout: {{ .Values.auth.cas.connectTimeout | quote }}
  auth-cas-read-timeout: {{ .Values.auth.cas.readTimeout | quote }}
  auth-cas-state-ttl: {{ .Values.auth.cas.stateTtl | quote }}
  auth-cas-max-response-bytes: {{ .Values.auth.cas.maxResponseBytes | quote }}
  auth-cas-attribute-subject: {{ .Values.auth.cas.attributes.subject | quote }}
  auth-cas-attribute-display-name: {{ .Values.auth.cas.attributes.displayName | quote }}
  auth-cas-attribute-email: {{ .Values.auth.cas.attributes.email | quote }}
  auth-cas-attribute-avatar-url: {{ .Values.auth.cas.attributes.avatarUrl | quote }}
  auth-dingtalk-enabled: {{ .Values.auth.dingtalk.enabled | quote }}
  auth-dingtalk-display-name: {{ .Values.auth.dingtalk.displayName | quote }}
  auth-dingtalk-authority: {{ .Values.auth.dingtalk.authority | quote }}
  auth-dingtalk-connect-timeout: {{ .Values.auth.dingtalk.connectTimeout | quote }}
  auth-dingtalk-read-timeout: {{ .Values.auth.dingtalk.readTimeout | quote }}
  auth-dingtalk-max-response-bytes: {{ .Values.auth.dingtalk.maxResponseBytes | quote }}
  builtin-skills-enabled: {{ .Values.builtinSkills.enabled | quote }}
