# Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

{{- $ingressName := (.Values.cluster).svIngressName | default (.Values.cluster).svNamespace }}
{{- if .Values.ingress.wallet }}
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: wallet-{{ (.Values.cluster).svNamespace }}
  namespace: {{ .Release.Namespace }}
spec:
  hosts:
    - "wallet.{{ $ingressName }}.{{ (.Values.cluster).hostname }}"
  gateways:
    - cluster-ingress/cn-http-gateway
  http:
    - match:
        - port: 443
          uri:
            prefix: "/api/validator/"
      route:
        - destination:
            port:
              number: 5003
            host: validator-app.{{ (.Values.cluster).svNamespace }}.svc.cluster.local
    - match:
        - port: 443
      route:
        - destination:
            port:
              number: 80
            host: wallet-web-ui.{{ (.Values.cluster).svNamespace }}.svc.cluster.local
---
{{- end }}
{{- if .Values.ingress.ans }}
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: ans-{{ (.Values.cluster).svNamespace }}
  namespace: {{ .Release.Namespace }}
spec:
  hosts:
    - "{{ .Values.spliceDomainNames.nameServiceDomain }}.{{ $ingressName }}.{{ (.Values.cluster).hostname }}"
  gateways:
    - cluster-ingress/cn-http-gateway
  http:
    - match:
        - port: 443
          uri:
            prefix: "/api/validator/"
      route:
        - destination:
            port:
              number: 5003
            host: validator-app.{{ (.Values.cluster).svNamespace }}.svc.cluster.local
    - match:
        - port: 443
      route:
        - destination:
            port:
              number: 80
            host: ans-web-ui.{{ (.Values.cluster).svNamespace }}.svc.cluster.local
---
{{- end }}
