package networkelement

import (
	"code.fbi.h-da.de/danet/gosdn/controller/conflict"
	"code.fbi.h-da.de/danet/gosdn/controller/interfaces/southbound"
	"code.fbi.h-da.de/danet/gosdn/controller/interfaces/transport"
	"github.com/google/uuid"
	"github.com/openconfig/ygot/ygot"
	"google.golang.org/protobuf/proto"

	tpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/transport"
)

// NetworkElement represents an Managed Network Element (MNE) which is managed by
// nucleus.
type NetworkElement interface {
	ID() uuid.UUID
	GetModel() ygot.GoStruct
	GetModelAsFilteredCopy() (ygot.GoStruct, error)
	SetModel(ygot.GoStruct)
	CreateModelCopy() (ygot.ValidatedGoStruct, error)
	Transport() transport.Transport
	Name() string
	SBI() southbound.SouthboundInterface
	ProcessResponse(proto.Message) error
	IsTransportValid() bool
	GetModelAsString() (string, error)
	TransportAddress() string
	GetMetadata() conflict.Metadata
}

// Details contains details of a network element used by the cSBI mechanism.
type Details struct {
	ID              string
	Address         string
	TransportOption *tpb.TransportOption
}

// LoadedNetworkElement represents a Managed Network Element that was loaeded
// by using the Load() method of the NetworkElementStore.
type LoadedNetworkElement struct {
	// ID represents the UUID of the LoadedNetworkElement.
	ID string `json:"id" bson:"_id"`
	// Name represents the name of the LoadedNetworkElement.
	Name string `json:"name,omitempty"`
	// TransportType represent the type of the transport in use of the LoadedNetworkElement.
	TransportType string `json:"transport_type,omitempty" bson:"transport_type,omitempty"`
	// TransportAddress represents the address from which the network element can be reached via the transport method.
	TransportAddress string `json:"transport_address,omitempty" bson:"transport_address,omitempty"`
	// TransportUsername is used for authentication via the transport method in use.
	TransportUsername string `json:"transport_username,omitempty" bson:"transport_username,omitempty"`
	// TransportPassword is used for authentication via the transport method in use.
	TransportPassword   string `json:"transport_password,omitempty" bson:"transport_password,omitempty"`
	TransportOptionCsbi bool   `json:"transport_option_csbi,omitempty" bson:"transport_option_csbi,omitempty"`

	// SBI indicates the southbound interface, which is used by this network element as UUID.
	SBI   string `json:"sbi"`
	Model string `json:"model,omitempty" bson:"model,omitempty"`

	Metadata conflict.Metadata `json:"metadata" bson:"metadata"`
}