package model

import (
	"github.com/tidbcloud/dataflow-service-e2e/internal/misc"
	"gopkg.in/yaml.v2"
)

type PulsarDimensions struct {
	NetworkType DataflowNetworkType `yaml:"networkType"`
}

func (t PulsarDimensions) Dimensions() map[string]string {
	return misc.StructToMap(t)
}

type PulsarRequirement struct {
	PulsarDimensions
}

func (t *PulsarRequirement) Type() string {
	return PULSAR
}

func (t *PulsarRequirement) IsDedicated() bool {
	// Notice: we don't support dedicated pulsar a specific case
	return false
}

type PulsarEntity struct {
	CreatedByDriver  bool
	PulsarDimensions `yaml:",inline"`
	AuthType         DataflowPulsarAuthType            `yaml:"authType"`
	User             string                            `yaml:"user"`
	Password         string                            `yaml:"password"`
	Token            string                            `yaml:"token"`
	Protocol         DataflowPulsarDestinationProtocol `yaml:"protocol"`
	Endpoint         string                            `yaml:"endpoint"`
	Tenant           string                            `yaml:"tenant"`
	Namespace        string                            `yaml:"namespace"`
	Topic            string                            `yaml:"topic"`
}

func (t *PulsarEntity) Type() string {
	return PULSAR
}
func (t *PulsarEntity) IsCreatedByDriver() bool {
	return t.CreatedByDriver
}

func (t *PulsarEntity) Copy() *PulsarEntity {
	data, err := yaml.Marshal(t)
	if err != nil {
		panic(err)
	}
	var copied PulsarEntity
	err = yaml.Unmarshal(data, &copied)
	return &copied
}

type PulsarEntities []*PulsarEntity

func (t PulsarEntities) ToDependencyEntities() []DependencyEntity {
	var entities []DependencyEntity
	for _, it := range t {
		entities = append(entities, it)
	}
	return entities
}
