// Code generated by Azure.Iot.Operations.ProtocolCompilerLib v0.10.0.0; DO NOT EDIT.
package schemaregistry

import (
	"github.com/Azure/iot-operations-sdks/go/protocol"
)

type SchemaRegistryClient struct {
	protocol.Listeners
	*PutCommandInvoker
	*GetCommandInvoker
}

const (
	ModelID = "dtmi:ms:adr:SchemaRegistry;2"
	CommandTopic = "adr/{modelId}/{commandName}"
)

func NewSchemaRegistryClient(
	app *protocol.Application,
	client protocol.MqttClient,
	opts ...protocol.Option,
) (*SchemaRegistryClient, error) {
	var err error

	clientOpts := []protocol.Option{
		protocol.WithTopicTokenNamespace("ex:"),
		protocol.WithTopicTokens{
			"modelId":    ModelID,
			"invokerClientId": client.ID(),
		},
	}

	var invokerOpts protocol.CommandInvokerOptions
	invokerOpts.ApplyOptions(opts, clientOpts...)

	schemaRegistryClient := &SchemaRegistryClient{}

	schemaRegistryClient.PutCommandInvoker, err = NewPutCommandInvoker(
		app,
		client,
		CommandTopic,
		&invokerOpts,
	)
	if err != nil {
		schemaRegistryClient.Close()
		return nil, err
	}
	schemaRegistryClient.Listeners = append(schemaRegistryClient.Listeners, schemaRegistryClient.PutCommandInvoker)

	schemaRegistryClient.GetCommandInvoker, err = NewGetCommandInvoker(
		app,
		client,
		CommandTopic,
		&invokerOpts,
	)
	if err != nil {
		schemaRegistryClient.Close()
		return nil, err
	}
	schemaRegistryClient.Listeners = append(schemaRegistryClient.Listeners, schemaRegistryClient.GetCommandInvoker)

	return schemaRegistryClient, nil
}
