{{- define "pcp-ui-service.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "pcp-ui-service.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- include "pcp-ui-service.name" . | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}

{{- define "pcp-ui-service.labels" -}}
app.kubernetes.io/name: {{ include "pcp-ui-service.name" . }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{- define "pcp-ui-service.serviceBaseUrl" -}}
{{- if .Values.app.serviceBaseUrl -}}
{{- .Values.app.serviceBaseUrl -}}
{{- else if and .Values.ingress.enabled .Values.ingress.host -}}
{{- $scheme := .Values.app.serviceBaseUrlScheme | default (ternary "https" "http" (gt (len .Values.ingress.tls) 0)) -}}
{{- printf "%s://%s" $scheme .Values.ingress.host -}}
{{- end -}}
{{- end -}}

{{- define "pcp-ui-service.managementBaseUrl" -}}
{{- if .Values.app.managementBaseUrl -}}
{{- .Values.app.managementBaseUrl -}}
{{- else -}}
{{- printf "http://%s:%v" (include "pcp-ui-service.fullname" .) .Values.service.port -}}
{{- end -}}
{{- end -}}

{{- define "pcp-ui-service.healthUrl" -}}
{{- if .Values.app.healthUrl -}}
{{- .Values.app.healthUrl -}}
{{- else -}}
{{- printf "%s/actuator/health" (include "pcp-ui-service.managementBaseUrl" .) -}}
{{- end -}}
{{- end -}}
