# EN: POS Web Client - Blazor WebAssembly Hosted (TPOS multi-vertical)
# VI: POS Web Client - Blazor WebAssembly Hosted (TPOS da nganh doc)
apiVersion: apps/v1
kind: Deployment
metadata:
  name: pos-web
  namespace: staging
  labels:
    app: pos-web
    environment: staging
    platform: goodgo
    tier: frontend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: pos-web
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: pos-web
        environment: staging
    spec:
      containers:
      - name: pos-web
        image: harbor.techbi.org/goodgo/web-client-tpos-net:staging
        ports:
        - containerPort: 8080
          protocol: TCP
        env:
        - name: ASPNETCORE_ENVIRONMENT
          value: "Staging"
        - name: ASPNETCORE_URLS
          value: "http://+:8080"
        # EN: API Gateway URL for backend communication
        # VI: URL API Gateway de giao tiep voi backend
        - name: ApiSettings__GatewayUrl
          value: "https://api.staging.goodgo.vn"
        # EN: IAM Service for auth
        # VI: IAM Service cho xac thuc
        - name: IamService__BaseUrl
          value: "http://iam-service:8080"
        # EN: YARP Reverse Proxy cluster addresses (K8s internal DNS)
        # VI: Dia chi cluster YARP Reverse Proxy (K8s internal DNS)
        - name: ReverseProxy__Clusters__iam-cluster__Destinations__destination1__Address
          value: "http://iam-service:8080"
        - name: ReverseProxy__Clusters__merchant-cluster__Destinations__destination1__Address
          value: "http://merchant-service:8080"
        - name: ReverseProxy__Clusters__catalog-cluster__Destinations__destination1__Address
          value: "http://catalog-service:8080"
        - name: ReverseProxy__Clusters__order-cluster__Destinations__destination1__Address
          value: "http://order-service:8080"
        # EN: BFF HTTP Proxy - Forward requests to microservice APIs
        # VI: BFF HTTP Proxy - Chuyen tiep request sang microservice APIs
        - name: MerchantService__BaseUrl
          value: "http://merchant-service:8080"
        - name: CatalogService__BaseUrl
          value: "http://catalog-service:8080"
        - name: OrderService__BaseUrl
          value: "http://order-service:8080"
        - name: InventoryService__BaseUrl
          value: "http://inventory-service:8080"
        - name: WalletService__BaseUrl
          value: "http://wallet-service:8080"
        - name: FnbEngine__BaseUrl
          value: "http://fnb-engine:8080"
        - name: StorageService__BaseUrl
          value: "http://storage-service:8080"
        resources:
          requests:
            memory: "256Mi"
            cpu: "250m"
          limits:
            memory: "512Mi"
            cpu: "500m"
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 15
          periodSeconds: 10
          timeoutSeconds: 5
          failureThreshold: 3
        readinessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 5
          periodSeconds: 5
          timeoutSeconds: 3
          failureThreshold: 3
        startupProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 5
          periodSeconds: 5
          failureThreshold: 12
---
apiVersion: v1
kind: Service
metadata:
  name: pos-web
  namespace: staging
  labels:
    app: pos-web
    environment: staging
spec:
  selector:
    app: pos-web
  ports:
  - name: http
    protocol: TCP
    port: 8080
    targetPort: 8080
  type: ClusterIP
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: pos-web-hpa
  namespace: staging
  labels:
    app: pos-web
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: pos-web
  minReplicas: 1
  maxReplicas: 2
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 75
