apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "pcp-tgu-ui-service.fullname" . }}
  labels:
    {{- include "pcp-tgu-ui-service.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "pcp-tgu-ui-service.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        {{- include "pcp-tgu-ui-service.labels" . | nindent 8 }}
        {{- with .Values.podLabels }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    spec:
      {{- with .Values.image.pullSecrets }}
      imagePullSecrets:
        {{- range . }}
        - name: {{ . }}
        {{- end }}
      {{- end }}
      containers:
        - name: {{ include "pcp-tgu-ui-service.name" . }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: {{ .Values.service.port }}
              protocol: TCP
          # APP_* читаются entrypoint'ом и попадают в /config.js → window.__NSTART_APP_ENV__.
          env:
            - name: APP_API_URL
              value: {{ .Values.app.apiUrl | quote }}
            - name: APP_AUTH_MODE
              value: {{ .Values.app.authMode | quote }}
            {{- if .Values.app.newStartIdUrl }}
            - name: APP_NEW_START_ID_URL
              value: {{ .Values.app.newStartIdUrl | quote }}
            {{- end }}
            {{- if .Values.app.newStartIdRealm }}
            - name: APP_NEW_START_ID_REALM
              value: {{ .Values.app.newStartIdRealm | quote }}
            {{- end }}
            {{- if .Values.app.newStartIdClientId }}
            - name: APP_NEW_START_ID_CLIENT_ID
              value: {{ .Values.app.newStartIdClientId | quote }}
            {{- end }}
            {{- with .Values.extraEnv }}
            {{- toYaml . | nindent 12 }}
            {{- end }}
          readinessProbe:
            httpGet:
              path: /healthz
              port: http
            initialDelaySeconds: 5
            periodSeconds: 15
            timeoutSeconds: 5
          livenessProbe:
            httpGet:
              path: /healthz
              port: http
            initialDelaySeconds: 10
            periodSeconds: 20
            timeoutSeconds: 5
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
