apiVersion: v1
kind: Service
metadata:
  name: {{ include "agent-monitor.fullname" . }}
  labels:
    {{- include "agent-monitor.labels" . | nindent 4 }}
  {{- with .Values.service.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.service.type }}
  # Sticky sessions for WebSocket connections
  sessionAffinity: ClientIP
  sessionAffinityConfig:
    clientIP:
      timeoutSeconds: 10800
  ports:
    - name: http
      port: {{ .Values.service.port }}
      targetPort: http
      protocol: TCP
      {{- if and (eq .Values.service.type "NodePort") .Values.service.nodePort }}
      nodePort: {{ .Values.service.nodePort }}
      {{- end }}
    {{- if .Values.mcp.enabled }}
    - name: mcp
      port: {{ .Values.mcp.port }}
      targetPort: mcp
      protocol: TCP
    {{- end }}
  selector:
    {{- include "agent-monitor.selectorLabels" . | nindent 4 }}
