package v1alpha1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

// +kubebuilder:object:root=true
// +kubebuilder:resource:categories=regionserver
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="PHASE",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// PrivateLinkEndpoint is the Schema for the PrivateLinkEndpoint API
type PrivateLinkEndpoint struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   PrivateLinkEndpointSpec   `json:"spec,omitempty"`
	Status PrivateLinkEndpointStatus `json:"status,omitempty"`
}

// +kubebuilder:validation:XValidation:rule="has(self.ownership) == has(oldSelf.ownership) && (!has(self.ownership) || self.ownership == oldSelf.ownership)",message="ownership is immutable"
type PrivateLinkEndpointSpec struct {
	Provider    string `json:"provider"`
	ServiceName string `json:"serviceName"`
	// +optional
	RootDomainName string `json:"rootDomainName"`
	// +optional
	DNSRecords map[string]string `json:"dnsRecords,omitempty"`
	Region     string            `json:"region"`
	// +optional
	ServiceRegion string    `json:"serviceRegion"`
	VPCRef        Reference `json:"vpcRef"`
	Zones         []string  `json:"zones,omitempty"`
	// +optional
	Tags map[string]string `json:"tags"`
	// Type distinguishes the private-link model. Empty defaults to
	// PrivateLinkEndpointTypeVPCEndpointService for backward compatibility.
	// +optional
	Type PrivateLinkEndpointType `json:"type,omitempty"`
	// MSKArn is the ARN of the customer's Amazon MSK cluster.
	// Only used when Type == PrivateLinkEndpointTypeAmazonMSK.
	// +optional
	MSKArn string `json:"mskArn,omitempty"`
	// AuthType is the MSK VPC connection authentication scheme.
	// Only used when Type == PrivateLinkEndpointTypeAmazonMSK.
	// +optional
	AuthType PrivateLinkEndpointAuthType `json:"authType,omitempty"`
	// +optional
	Ownership *ResourceOwnership `json:"ownership,omitempty"`
}

// PrivateLinkEndpointType distinguishes the private-link model.
type PrivateLinkEndpointType string

const (
	PrivateLinkEndpointTypeVPCEndpointService PrivateLinkEndpointType = "vpc_endpoint_service"
	PrivateLinkEndpointTypeAmazonMSK          PrivateLinkEndpointType = "amazon_msk"
)

// PrivateLinkEndpointAuthType is the authentication scheme of an MSK VPC connection.
type PrivateLinkEndpointAuthType string

const (
	PrivateLinkEndpointAuthTypeSASLScram PrivateLinkEndpointAuthType = "sasl_scram"
	PrivateLinkEndpointAuthTypeSASLIAM   PrivateLinkEndpointAuthType = "sasl_iam"
)

type PrivateLinkEndpointStatus struct {
	// +optional
	ID string `json:"id,omitempty"`
	// +optional
	Phase PrivateLinkEndpointPhase `json:"phase,omitempty"`
	// +optional
	Message string `json:"message,omitempty"`
	// +optional
	EndpointAddress string `json:"endpointAddress,omitempty"`
	// ZonesAddresses represents endpoint addresses in every availability zones
	// +optional
	ZonesAddresses map[string]string `json:"zonesAddresses,omitempty"`
	// VPCConnectionArn is the ARN of the created MSK VPC connection (Amazon MSK only).
	// +optional
	VPCConnectionArn string `json:"vpcConnectionArn,omitempty"`
	// BootstrapBroker is the MSK VPC-connectivity bootstrap broker string (Amazon MSK only).
	// +optional
	BootstrapBroker string `json:"bootstrapBroker,omitempty"`
}

type PrivateLinkEndpointPhase string

const (
	PrivateLinkEndpointPhaseCreating          PrivateLinkEndpointPhase = "Creating"
	PrivateLinkEndpointPhasePending           PrivateLinkEndpointPhase = "Pending"
	PrivateLinkEndpointPhasePendingAcceptance PrivateLinkEndpointPhase = "PendingAcceptance"
	PrivateLinkEndpointPhaseEndpointAvailable PrivateLinkEndpointPhase = "EndpointAvailable"
	PrivateLinkEndpointPhaseAvailable         PrivateLinkEndpointPhase = "Available"
	PrivateLinkEndpointPhaseFailed            PrivateLinkEndpointPhase = "Failed"
	PrivateLinkEndpointPhaseRejected          PrivateLinkEndpointPhase = "Rejected"
	PrivateLinkEndpointPhaseDeleting          PrivateLinkEndpointPhase = "Deleting"
)

// +kubebuilder:object:root=true
type PrivateLinkEndpointList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata"`
	Items           []PrivateLinkEndpoint `json:"items"`
}

func init() {
	SchemeBuilder.Register(&PrivateLinkEndpoint{}, &PrivateLinkEndpointList{})
}
