// Copyright (c) 2023 Volvo Car Corporation
// SPDX-License-Identifier: Apache-2.0

// Code generated by lingon. EDIT AS MUCH AS YOU LIKE.

package nats

import (
	ku "github.com/golingon/lingon/pkg/kubeutil"
	"github.com/golingon/lingoneks/meta"
	appsv1 "k8s.io/api/apps/v1"
	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var (
	natsBox = "nats-box"

	natsBoxImg = meta.ContainerImg{
		Image: "natsio/nats-box",
		Tag:   "0.13.8",
	}

	natsBoxLabel = map[string]string{"app": natsBox}
)

var BoxDeploy = &appsv1.Deployment{
	TypeMeta: ku.TypeDeploymentV1,
	ObjectMeta: metav1.ObjectMeta{
		Labels:    natsBoxLabel,
		Name:      natsBox,
		Namespace: N.Namespace,
	},
	Spec: appsv1.DeploymentSpec{
		Replicas: P(int32(1)),
		Selector: &metav1.LabelSelector{MatchLabels: natsBoxLabel},
		Template: corev1.PodTemplateSpec{
			ObjectMeta: metav1.ObjectMeta{Labels: natsBoxLabel},
			Spec: corev1.PodSpec{
				Containers: []corev1.Container{
					{
						Command: []string{"tail", "-f", "/dev/null"},
						Env: []corev1.EnvVar{
							{
								Name:  "NATS_URL",
								Value: "nats",
							},
						},
						Image:           natsBoxImg.URL(),
						ImagePullPolicy: corev1.PullIfNotPresent,
						Name:            natsBox,
					},
				},
			},
		},
	},
}

var TestRequestReplyPO = &corev1.Pod{
	TypeMeta: ku.TypePodV1,
	ObjectMeta: metav1.ObjectMeta{
		// Annotations: map[string]string{"helm.sh/hook": "test"},
		Labels: map[string]string{
			"app":   "nats-test-request-reply",
			"chart": "nats-0.19.13",
		},
		Name: "nats-test-request-reply",
	},
	Spec: corev1.PodSpec{
		Containers: []corev1.Container{
			{
				Command: []string{
					"/bin/sh",
					"-ec",
					`nats reply -s nats://$NATS_HOST:4222 'name.>' --command "echo 1" & `,
					`"&&"`,
					`name=$(nats request -s nats://$NATS_HOST:4222 name.test '' 2>/dev/null)`,
					`"&&"`,
					`[ $name = test ]`,
				},
				Env: []corev1.EnvVar{
					{
						Name:  "NATS_HOST",
						Value: "nats",
					},
				},
				Image: natsBoxImg.URL(),
				Name:  natsBox,
			},
		},
		RestartPolicy: corev1.RestartPolicyNever,
	},
}
