// Code generated by "./generator ./session/com.lingmo.shutdownfront"; DO NOT EDIT.

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

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 ShutdownFront interface {
	shutdownfront // interface com.lingmo.shutdownFront
	proxy.Object
}

type objectShutdownFront struct {
	interfaceShutdownfront // interface com.lingmo.shutdownFront
	proxy.ImplObject
}

func NewShutdownFront(conn *dbus.Conn) ShutdownFront {
	obj := new(objectShutdownFront)
	obj.ImplObject.Init_(conn, "com.lingmo.shutdownFront", "/com/lingmo/shutdownFront")
	return obj
}

type shutdownfront interface {
	GoHibernate(flags dbus.Flags, ch chan *dbus.Call) *dbus.Call
	Hibernate(flags dbus.Flags) error
	GoLock(flags dbus.Flags, ch chan *dbus.Call) *dbus.Call
	Lock(flags dbus.Flags) error
	GoLogout(flags dbus.Flags, ch chan *dbus.Call) *dbus.Call
	Logout(flags dbus.Flags) error
	GoRestart(flags dbus.Flags, ch chan *dbus.Call) *dbus.Call
	Restart(flags dbus.Flags) error
	GoShow(flags dbus.Flags, ch chan *dbus.Call) *dbus.Call
	Show(flags dbus.Flags) error
	GoShutdown(flags dbus.Flags, ch chan *dbus.Call) *dbus.Call
	Shutdown(flags dbus.Flags) error
	GoSuspend(flags dbus.Flags, ch chan *dbus.Call) *dbus.Call
	Suspend(flags dbus.Flags) error
	GoSwitchUser(flags dbus.Flags, ch chan *dbus.Call) *dbus.Call
	SwitchUser(flags dbus.Flags) error
	ConnectChangKey(cb func(keyEvent string)) (dbusutil.SignalHandlerId, error)
}

type interfaceShutdownfront struct{}

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

func (*interfaceShutdownfront) GetInterfaceName_() string {
	return "com.lingmo.shutdownFront"
}

// method Hibernate

func (v *interfaceShutdownfront) GoHibernate(flags dbus.Flags, ch chan *dbus.Call) *dbus.Call {
	return v.GetObject_().Go_(v.GetInterfaceName_()+".Hibernate", flags, ch)
}

func (v *interfaceShutdownfront) Hibernate(flags dbus.Flags) error {
	return (<-v.GoHibernate(flags, make(chan *dbus.Call, 1)).Done).Err
}

// method Lock

func (v *interfaceShutdownfront) GoLock(flags dbus.Flags, ch chan *dbus.Call) *dbus.Call {
	return v.GetObject_().Go_(v.GetInterfaceName_()+".Lock", flags, ch)
}

func (v *interfaceShutdownfront) Lock(flags dbus.Flags) error {
	return (<-v.GoLock(flags, make(chan *dbus.Call, 1)).Done).Err
}

// method Logout

func (v *interfaceShutdownfront) GoLogout(flags dbus.Flags, ch chan *dbus.Call) *dbus.Call {
	return v.GetObject_().Go_(v.GetInterfaceName_()+".Logout", flags, ch)
}

func (v *interfaceShutdownfront) Logout(flags dbus.Flags) error {
	return (<-v.GoLogout(flags, make(chan *dbus.Call, 1)).Done).Err
}

// method Restart

func (v *interfaceShutdownfront) GoRestart(flags dbus.Flags, ch chan *dbus.Call) *dbus.Call {
	return v.GetObject_().Go_(v.GetInterfaceName_()+".Restart", flags, ch)
}

func (v *interfaceShutdownfront) Restart(flags dbus.Flags) error {
	return (<-v.GoRestart(flags, make(chan *dbus.Call, 1)).Done).Err
}

// method Show

func (v *interfaceShutdownfront) GoShow(flags dbus.Flags, ch chan *dbus.Call) *dbus.Call {
	return v.GetObject_().Go_(v.GetInterfaceName_()+".Show", flags, ch)
}

func (v *interfaceShutdownfront) Show(flags dbus.Flags) error {
	return (<-v.GoShow(flags, make(chan *dbus.Call, 1)).Done).Err
}

// method Shutdown

func (v *interfaceShutdownfront) GoShutdown(flags dbus.Flags, ch chan *dbus.Call) *dbus.Call {
	return v.GetObject_().Go_(v.GetInterfaceName_()+".Shutdown", flags, ch)
}

func (v *interfaceShutdownfront) Shutdown(flags dbus.Flags) error {
	return (<-v.GoShutdown(flags, make(chan *dbus.Call, 1)).Done).Err
}

// method Suspend

func (v *interfaceShutdownfront) GoSuspend(flags dbus.Flags, ch chan *dbus.Call) *dbus.Call {
	return v.GetObject_().Go_(v.GetInterfaceName_()+".Suspend", flags, ch)
}

func (v *interfaceShutdownfront) Suspend(flags dbus.Flags) error {
	return (<-v.GoSuspend(flags, make(chan *dbus.Call, 1)).Done).Err
}

// method SwitchUser

func (v *interfaceShutdownfront) GoSwitchUser(flags dbus.Flags, ch chan *dbus.Call) *dbus.Call {
	return v.GetObject_().Go_(v.GetInterfaceName_()+".SwitchUser", flags, ch)
}

func (v *interfaceShutdownfront) SwitchUser(flags dbus.Flags) error {
	return (<-v.GoSwitchUser(flags, make(chan *dbus.Call, 1)).Done).Err
}

// signal ChangKey

func (v *interfaceShutdownfront) ConnectChangKey(cb func(keyEvent string)) (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_(), "ChangKey", obj.Path_(), obj.ServiceName_())

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

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