{{- if eq .Values.service.type "LoadBalancer" }}
apiVersion: v1
kind: Service
metadata:
  name: {{ include "omada-controller.fullname" . }}
  labels:
    {{- include "omada-controller.labels" . | nindent 4 }}
  {{- with .Values.service.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.manage.port }}
      targetPort: 8088
      protocol: TCP
      name: manage
    - port: {{ .Values.service.managessl.port }}
      targetPort: 8043
      protocol: TCP
      name: managessl
    - port: {{ .Values.service.portalssl.port }}
      targetPort: {{ .Values.env.MANAGE_HTTPS_PORT }}
      protocol: TCP
      name: portalssl
    - port: {{ .Values.service.eapmanage.port }}
      targetPort: 29811
      protocol: TCP
      name: eapmanage
    - port: {{ .Values.service.eapadopt.port }}
      targetPort: 29812
      protocol: TCP
      name: eapadopt
    - port: {{ .Values.service.eapupgrade.port }}
      targetPort: 29813
      protocol: TCP
      name: eapupgrade
    - port: {{ .Values.service.managev2.port }}
      targetPort: 29814
      protocol: TCP
      name: managev2
  selector:
    {{- include "omada-controller.selectorLabels" . | nindent 4 }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "omada-controller.fullname" . }}-udp-lb
  labels:
    {{- include "omada-controller.labels" . | nindent 4 }}
  {{- with .Values.service.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.eapdiscovery.port }}
      targetPort: 29810
      protocol: UDP
      name: eapdiscovery
  selector:
    {{- include "omada-controller.selectorLabels" . | nindent 4 }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "omada-controller.fullname" . }}-udp
  labels:
    {{- include "omada-controller.labels" . | nindent 4 }}
spec:
  type: NodePort
  ports:
    - port: {{ .Values.service.eapdiscovery.port }}
      targetPort: 29810
      protocol: UDP
      name: eapdiscovery
  selector:
    {{- include "omada-controller.selectorLabels" . | nindent 4 }}
  {{- if .Values.service.externalIPs.enabled }}
  externalTrafficPolicy: Local
  externalIPs:{{- range .Values.service.externalIPs.ip }}
  - {{.}}{{- end }}
  {{- end }}
{{ else }}
apiVersion: v1
kind: Service
metadata:
  name: {{ include "omada-controller.fullname" . }}
  labels:
    {{- include "omada-controller.labels" . | nindent 4 }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.manage.port }}
      targetPort: 8088
      protocol: TCP
      name: manage
    - port: {{ .Values.service.managessl.port }}
      targetPort: 8043
      protocol: TCP
      name: managessl
    - port: {{ .Values.service.portalssl.port }}
      targetPort: 8843
      protocol: TCP
      name: portalssl
    - port: {{ .Values.service.eapdiscovery.port }}
      targetPort: 29810
      protocol: UDP
      name: eapdiscovery
    - port: {{ .Values.service.eapmanage.port }}
      targetPort: 29811
      protocol: TCP
      name: eapmanage
    - port: {{ .Values.service.eapadopt.port }}
      targetPort: 29812
      protocol: TCP
      name: eapadopt
    - port: {{ .Values.service.eapupgrade.port }}
      targetPort: 29813
      protocol: TCP
      name: eapupgrade
    - port: {{ .Values.service.managev2.port }}
      targetPort: 29814
      protocol: TCP
      name: managev2
  {{- if .Values.service.externalIPs.enabled }}
  externalTrafficPolicy: Local
  externalIPs:{{- range .Values.service.externalIPs.ip }}
  - {{.}}{{- end }}
  {{- end }}
  selector:
    {{- include "omada-controller.selectorLabels" . | nindent 4 }}
{{ end }}
