//go:build !ignore_autogenerated
// +build !ignore_autogenerated

// Code generated by mga tool. DO NOT EDIT.

package auth

import (
	"context"
	"emperror.dev/errors"
)

// EventBus is a generic event bus.
type EventBus interface {
	// Publish sends an event to the underlying message bus.
	Publish(ctx context.Context, event interface{}) error
}

// OrganizationEventDispatcher dispatches events through the underlying generic event bus.
type OrganizationEventDispatcher struct {
	bus EventBus
}

// NewOrganizationEventDispatcher returns a new OrganizationEventDispatcher instance.
func NewOrganizationEventDispatcher(bus EventBus) OrganizationEventDispatcher {
	return OrganizationEventDispatcher{bus: bus}
}

// OrganizationCreated dispatches a(n) OrganizationCreated event.
func (d OrganizationEventDispatcher) OrganizationCreated(ctx context.Context, event OrganizationCreated) error {
	err := d.bus.Publish(ctx, event)
	if err != nil {
		return errors.WithDetails(errors.WithMessage(err, "failed to dispatch event"), "event", "OrganizationCreated")
	}

	return nil
}
