{{- if .Values.mcpServer.enabled -}}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "skill-seekers.fullname" . }}-mcp
  labels:
    {{- include "skill-seekers.labels" . | nindent 4 }}
    app.kubernetes.io/component: mcp-server
spec:
  {{- if not .Values.mcpServer.autoscaling.enabled }}
  replicas: {{ .Values.mcpServer.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "skill-seekers.selectorLabels" . | nindent 6 }}
      app.kubernetes.io/component: mcp-server
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
        checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
        {{- with .Values.mcpServer.podAnnotations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      labels:
        {{- include "skill-seekers.selectorLabels" . | nindent 8 }}
        app.kubernetes.io/component: mcp-server
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "skill-seekers.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.mcpServer.podSecurityContext | nindent 8 }}
      containers:
      - name: mcp-server
        securityContext:
          {{- toYaml .Values.mcpServer.securityContext | nindent 12 }}
        image: "{{ .Values.mcpServer.image.repository }}:{{ .Values.mcpServer.image.tag | default .Chart.AppVersion }}"
        imagePullPolicy: {{ .Values.mcpServer.image.pullPolicy }}
        ports:
        - name: http
          containerPort: {{ .Values.mcpServer.service.targetPort }}
          protocol: TCP
        envFrom:
        - configMapRef:
            name: {{ include "skill-seekers.fullname" . }}
        - secretRef:
            name: {{ include "skill-seekers.fullname" . }}
        livenessProbe:
          {{- toYaml .Values.mcpServer.livenessProbe | nindent 12 }}
        readinessProbe:
          {{- toYaml .Values.mcpServer.readinessProbe | nindent 12 }}
        resources:
          {{- toYaml .Values.mcpServer.resources | nindent 12 }}
        volumeMounts:
        - name: data
          mountPath: /data
        - name: output
          mountPath: /output
        - name: configs
          mountPath: /configs
          readOnly: true
      volumes:
      - name: data
        {{- if .Values.persistence.data.enabled }}
        persistentVolumeClaim:
          claimName: {{ .Values.persistence.data.existingClaim | default (printf "%s-data" (include "skill-seekers.fullname" .)) }}
        {{- else }}
        emptyDir: {}
        {{- end }}
      - name: output
        {{- if .Values.persistence.output.enabled }}
        persistentVolumeClaim:
          claimName: {{ .Values.persistence.output.existingClaim | default (printf "%s-output" (include "skill-seekers.fullname" .)) }}
        {{- else }}
        emptyDir: {}
        {{- end }}
      - name: configs
        {{- if .Values.persistence.configs.enabled }}
        persistentVolumeClaim:
          claimName: {{ .Values.persistence.configs.existingClaim | default (printf "%s-configs" (include "skill-seekers.fullname" .)) }}
        {{- else }}
        emptyDir: {}
        {{- end }}
      {{- with .Values.mcpServer.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.mcpServer.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.mcpServer.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
{{- end }}
