// Code generated by eventc event; DO NOT EDIT.

package ec

import (
	"fmt"
	event "git.golaxy.org/tiny/event"
	iface "git.golaxy.org/tiny/utils/iface"
)

type iAutoEventEntityDestroySelf interface {
	EventEntityDestroySelf() event.IEvent
}

func BindEventEntityDestroySelf(auto iAutoEventEntityDestroySelf, subscriber EventEntityDestroySelf, priority ...int32) event.Hook {
	if auto == nil {
		panic(fmt.Errorf("%w: %w: auto is nil", event.ErrEvent, event.ErrArgs))
	}
	return event.Bind[EventEntityDestroySelf](auto.EventEntityDestroySelf(), subscriber, priority...)
}

func _EmitEventEntityDestroySelf(auto iAutoEventEntityDestroySelf, entity Entity) {
	if auto == nil {
		panic(fmt.Errorf("%w: %w: auto is nil", event.ErrEvent, event.ErrArgs))
	}
	event.UnsafeEvent(auto.EventEntityDestroySelf()).Emit(func(subscriber iface.Cache) bool {
		iface.Cache2Iface[EventEntityDestroySelf](subscriber).OnEntityDestroySelf(entity)
		return true
	})
}

func _EmitEventEntityDestroySelfWithInterrupt(auto iAutoEventEntityDestroySelf, interrupt func(entity Entity) bool, entity Entity) {
	if auto == nil {
		panic(fmt.Errorf("%w: %w: auto is nil", event.ErrEvent, event.ErrArgs))
	}
	event.UnsafeEvent(auto.EventEntityDestroySelf()).Emit(func(subscriber iface.Cache) bool {
		if interrupt != nil {
			if interrupt(entity) {
				return false
			}
		}
		iface.Cache2Iface[EventEntityDestroySelf](subscriber).OnEntityDestroySelf(entity)
		return true
	})
}

func HandleEventEntityDestroySelf(fun func(entity Entity)) EventEntityDestroySelfHandler {
	return EventEntityDestroySelfHandler(fun)
}

type EventEntityDestroySelfHandler func(entity Entity)

func (h EventEntityDestroySelfHandler) OnEntityDestroySelf(entity Entity) {
	h(entity)
}
