package status_test

import (
	"testing"

	"github.com/awslabs/operatorpkg/test"
	"github.com/onsi/ginkgo/v2"
	"github.com/onsi/gomega"
	"github.com/samber/lo"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/apimachinery/pkg/runtime/schema"
	"k8s.io/client-go/kubernetes/scheme"
)

func Test(t *testing.T) {
	lo.Must0(SchemeBuilder.AddToScheme(scheme.Scheme))
	gomega.RegisterFailHandler(ginkgo.Fail)
	ginkgo.RunSpecs(t, "Status")
}

var (
	SchemeBuilder = runtime.NewSchemeBuilder(func(scheme *runtime.Scheme) error {
		scheme.AddKnownTypes(schema.GroupVersion{Group: test.APIGroup, Version: "v1alpha1"}, &test.CustomObject{}, &TestGenericObject{})
		return nil
	})
)

// +k8s:deepcopy-gen=true
// +kubebuilder:object:root=true
type TestGenericObject struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Status            TestGenericStatus `json:"status"`
}

// +k8s:deepcopy-gen=true
type TestGenericStatus struct {
	Conditions []metav1.Condition `json:"conditions"`
}

const (
	// Normal Conditions
	ConditionTypeFoo = "Foo"
	ConditionTypeBar = "Bar"
	// Abnormal Conditions
	ConditionTypeBaz = "Baz"
)

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *TestGenericObject) DeepCopyInto(out *TestGenericObject) {
	*out = *in
	out.TypeMeta = in.TypeMeta
	in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
	in.Status.DeepCopyInto(&out.Status)
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestObject.
func (in *TestGenericObject) DeepCopy() *TestGenericObject {
	if in == nil {
		return nil
	}
	out := new(TestGenericObject)
	in.DeepCopyInto(out)
	return out
}

// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *TestGenericObject) DeepCopyObject() runtime.Object {
	if c := in.DeepCopy(); c != nil {
		return c
	}
	return nil
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *TestGenericStatus) DeepCopyInto(out *TestGenericStatus) {
	*out = *in
	if in.Conditions != nil {
		in, out := &in.Conditions, &out.Conditions
		*out = make([]metav1.Condition, len(*in))
		for i := range *in {
			(*in)[i].DeepCopyInto(&(*out)[i])
		}
	}
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestStatus.
func (in *TestGenericStatus) DeepCopy() *TestGenericStatus {
	if in == nil {
		return nil
	}
	out := new(TestGenericStatus)
	in.DeepCopyInto(out)
	return out
}
