// Code generated by girgen. DO NOT EDIT.

package adw

import (
	"runtime"
	"unsafe"

	"github.com/diamondburned/gotk4/pkg/core/gbox"
	coreglib "github.com/diamondburned/gotk4/pkg/core/glib"
)

// #include <stdlib.h>
// #include <adwaita.h>
// #include <glib-object.h>
// extern void callbackDelete(gpointer);
// extern void _gotk4_adw1_AnimationTargetFunc(double, gpointer);
import "C"

// GType values.
var (
	GTypeAnimationTarget         = coreglib.Type(C.adw_animation_target_get_type())
	GTypeCallbackAnimationTarget = coreglib.Type(C.adw_callback_animation_target_get_type())
)

func init() {
	coreglib.RegisterGValueMarshalers([]coreglib.TypeMarshaler{
		coreglib.TypeMarshaler{T: GTypeAnimationTarget, F: marshalAnimationTarget},
		coreglib.TypeMarshaler{T: GTypeCallbackAnimationTarget, F: marshalCallbackAnimationTarget},
	})
}

// AnimationTargetFunc: prototype for animation targets based on user callbacks.
type AnimationTargetFunc func(value float64)

// AnimationTarget represents a value animation can animate.
type AnimationTarget struct {
	_ [0]func() // equal guard
	*coreglib.Object
}

var (
	_ coreglib.Objector = (*AnimationTarget)(nil)
)

// AnimationTargetter describes types inherited from class AnimationTarget.
//
// To get the original type, the caller must assert this to an interface or
// another type.
type AnimationTargetter interface {
	coreglib.Objector
	baseAnimationTarget() *AnimationTarget
}

var _ AnimationTargetter = (*AnimationTarget)(nil)

func wrapAnimationTarget(obj *coreglib.Object) *AnimationTarget {
	return &AnimationTarget{
		Object: obj,
	}
}

func marshalAnimationTarget(p uintptr) (interface{}, error) {
	return wrapAnimationTarget(coreglib.ValueFromNative(unsafe.Pointer(p)).Object()), nil
}

func (v *AnimationTarget) baseAnimationTarget() *AnimationTarget {
	return v
}

// BaseAnimationTarget returns the underlying base object.
func BaseAnimationTarget(obj AnimationTargetter) *AnimationTarget {
	return obj.baseAnimationTarget()
}

// CallbackAnimationTarget: animationtarget that calls a given callback during
// the animation.
type CallbackAnimationTarget struct {
	_ [0]func() // equal guard
	AnimationTarget
}

var (
	_ AnimationTargetter = (*CallbackAnimationTarget)(nil)
)

func wrapCallbackAnimationTarget(obj *coreglib.Object) *CallbackAnimationTarget {
	return &CallbackAnimationTarget{
		AnimationTarget: AnimationTarget{
			Object: obj,
		},
	}
}

func marshalCallbackAnimationTarget(p uintptr) (interface{}, error) {
	return wrapCallbackAnimationTarget(coreglib.ValueFromNative(unsafe.Pointer(p)).Object()), nil
}

// NewCallbackAnimationTarget creates a new AdwAnimationTarget that calls the
// given callback during the animation.
//
// The function takes the following parameters:
//
//   - callback to call.
//
// The function returns the following values:
//
//   - callbackAnimationTarget: newly created callback target.
func NewCallbackAnimationTarget(callback AnimationTargetFunc) *CallbackAnimationTarget {
	var _arg1 C.AdwAnimationTargetFunc // out
	var _arg2 C.gpointer
	var _arg3 C.GDestroyNotify
	var _cret *C.AdwAnimationTarget // in

	_arg1 = (*[0]byte)(C._gotk4_adw1_AnimationTargetFunc)
	_arg2 = C.gpointer(gbox.Assign(callback))
	_arg3 = (C.GDestroyNotify)((*[0]byte)(C.callbackDelete))

	_cret = C.adw_callback_animation_target_new(_arg1, _arg2, _arg3)
	runtime.KeepAlive(callback)

	var _callbackAnimationTarget *CallbackAnimationTarget // out

	_callbackAnimationTarget = wrapCallbackAnimationTarget(coreglib.AssumeOwnership(unsafe.Pointer(_cret)))

	return _callbackAnimationTarget
}
