// Code generated by "./generator ./system/org.lingmo.imageblur1"; DO NOT EDIT.

// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
package imageblur1

import (
	"errors"
	"fmt"
	"unsafe"

	"github.com/godbus/dbus/v5"
	"github.com/LingmoOS/golang-github-lingmo-go-lib/dbusutil"
	"github.com/LingmoOS/golang-github-lingmo-go-lib/dbusutil/proxy"
)

type ImageBlur interface {
	imageBlur // interface org.lingmo.ImageBlur1
	proxy.Object
}

type objectImageBlur struct {
	interfaceImageBlur // interface org.lingmo.ImageBlur1
	proxy.ImplObject
}

func NewImageBlur(conn *dbus.Conn) ImageBlur {
	obj := new(objectImageBlur)
	obj.ImplObject.Init_(conn, "org.lingmo.ImageBlur1", "/org/lingmo/ImageBlur1")
	return obj
}

type imageBlur interface {
	GoDelete(flags dbus.Flags, ch chan *dbus.Call, file string) *dbus.Call
	Delete(flags dbus.Flags, file string) error
	GoGet(flags dbus.Flags, ch chan *dbus.Call, source string) *dbus.Call
	Get(flags dbus.Flags, source string) (string, error)
	ConnectBlurDone(cb func(imgFile string, imgBlurFile string, ok bool)) (dbusutil.SignalHandlerId, error)
}

type interfaceImageBlur struct{}

func (v *interfaceImageBlur) GetObject_() *proxy.ImplObject {
	return (*proxy.ImplObject)(unsafe.Pointer(v))
}

func (*interfaceImageBlur) GetInterfaceName_() string {
	return "org.lingmo.ImageBlur1"
}

// method Delete

func (v *interfaceImageBlur) GoDelete(flags dbus.Flags, ch chan *dbus.Call, file string) *dbus.Call {
	return v.GetObject_().Go_(v.GetInterfaceName_()+".Delete", flags, ch, file)
}

func (v *interfaceImageBlur) Delete(flags dbus.Flags, file string) error {
	return (<-v.GoDelete(flags, make(chan *dbus.Call, 1), file).Done).Err
}

// method Get

func (v *interfaceImageBlur) GoGet(flags dbus.Flags, ch chan *dbus.Call, source string) *dbus.Call {
	return v.GetObject_().Go_(v.GetInterfaceName_()+".Get", flags, ch, source)
}

func (*interfaceImageBlur) StoreGet(call *dbus.Call) (blurred string, err error) {
	err = call.Store(&blurred)
	return
}

func (v *interfaceImageBlur) Get(flags dbus.Flags, source string) (string, error) {
	return v.StoreGet(
		<-v.GoGet(flags, make(chan *dbus.Call, 1), source).Done)
}

// signal BlurDone

func (v *interfaceImageBlur) ConnectBlurDone(cb func(imgFile string, imgBlurFile string, ok bool)) (dbusutil.SignalHandlerId, error) {
	if cb == nil {
		return 0, errors.New("nil callback")
	}
	obj := v.GetObject_()
	rule := fmt.Sprintf(
		"type='signal',interface='%s',member='%s',path='%s',sender='%s'",
		v.GetInterfaceName_(), "BlurDone", obj.Path_(), obj.ServiceName_())

	sigRule := &dbusutil.SignalRule{
		Path: obj.Path_(),
		Name: v.GetInterfaceName_() + ".BlurDone",
	}
	handlerFunc := func(sig *dbus.Signal) {
		var imgFile string
		var imgBlurFile string
		var ok bool
		err := dbus.Store(sig.Body, &imgFile, &imgBlurFile, &ok)
		if err == nil {
			cb(imgFile, imgBlurFile, ok)
		}
	}

	return obj.ConnectSignal_(rule, sigRule, handlerFunc)
}
