/*This file is automatically generated by pkg.deepin.io/dbus-generator. Don't edit it*/
package timedate

import "pkg.deepin.io/lib/dbus"
import "pkg.deepin.io/lib/dbus/property"
import "reflect"
import "sync"
import "runtime"
import "fmt"
import "errors"

/*prevent compile error*/
var _ = fmt.Println
var _ = runtime.SetFinalizer
var _ = sync.NewCond
var _ = reflect.TypeOf
var _ = property.BaseObserver{}

type Timedate struct {
	Path     dbus.ObjectPath
	DestName string
	core     *dbus.Object

	signals       map[<-chan *dbus.Signal]struct{}
	signalsLocker sync.Mutex

	CanNTP          *dbusPropertyTimedateCanNTP
	NTP             *dbusPropertyTimedateNTP
	LocalRTC        *dbusPropertyTimedateLocalRTC
	Timezone        *dbusPropertyTimedateTimezone
	Use24HourFormat *dbusPropertyTimedateUse24HourFormat
	DSTOffset       *dbusPropertyTimedateDSTOffset
	UserTimezones   *dbusPropertyTimedateUserTimezones
}

func (obj *Timedate) _createSignalChan() <-chan *dbus.Signal {
	obj.signalsLocker.Lock()
	ch := getBus().Signal()
	obj.signals[ch] = struct{}{}
	obj.signalsLocker.Unlock()
	return ch
}
func (obj *Timedate) _deleteSignalChan(ch <-chan *dbus.Signal) {
	obj.signalsLocker.Lock()
	delete(obj.signals, ch)
	getBus().DetachSignal(ch)
	obj.signalsLocker.Unlock()
}
func DestroyTimedate(obj *Timedate) {
	obj.signalsLocker.Lock()
	defer obj.signalsLocker.Unlock()
	if obj.signals == nil {
		return
	}
	for ch, _ := range obj.signals {
		getBus().DetachSignal(ch)
	}
	obj.signals = nil

	runtime.SetFinalizer(obj, nil)

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.DBus.Properties',sender='" + obj.DestName + "',member='PropertiesChanged'")
	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.Timedate',sender='" + obj.DestName + "',member='PropertiesChanged'")

	obj.CanNTP.Reset()
	obj.NTP.Reset()
	obj.LocalRTC.Reset()
	obj.Timezone.Reset()
	obj.Use24HourFormat.Reset()
	obj.DSTOffset.Reset()
	obj.UserTimezones.Reset()
}

func (obj *Timedate) AddUserTimezone(arg0 string) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Timedate.AddUserTimezone", 0, arg0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Timedate) DeleteUserTimezone(arg0 string) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Timedate.DeleteUserTimezone", 0, arg0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Timedate) GetZoneInfo(arg0 string) (arg1 []interface{}, _err error) {
	_err = obj.core.Call("com.deepin.daemon.Timedate.GetZoneInfo", 0, arg0).Store(&arg1)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Timedate) GetZoneList() (arg0 []string, _err error) {
	_err = obj.core.Call("com.deepin.daemon.Timedate.GetZoneList", 0).Store(&arg0)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Timedate) SetDate(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 int32, arg5 int32, arg6 int32) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Timedate.SetDate", 0, arg0, arg1, arg2, arg3, arg4, arg5, arg6).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Timedate) SetLocalRTC(arg0 bool, arg1 bool) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Timedate.SetLocalRTC", 0, arg0, arg1).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Timedate) SetNTP(arg0 bool) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Timedate.SetNTP", 0, arg0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Timedate) SetTime(arg0 int64, arg1 bool) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Timedate.SetTime", 0, arg0, arg1).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Timedate) SetTimezone(arg0 string) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Timedate.SetTimezone", 0, arg0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

type dbusPropertyTimedateCanNTP struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyTimedateCanNTP) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Timedate.CanNTP is not writable")
}

func (this *dbusPropertyTimedateCanNTP) Get() bool {
	v, _ := this.GetValue()
	return v.(bool)
}
func (this *dbusPropertyTimedateCanNTP) GetValue() (interface{} /*bool*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "com.deepin.daemon.Timedate", "CanNTP").Store(&r)
	if err == nil && r.Signature().String() == "b" {
		return r.Value().(bool), nil
	}
	return *new(bool), err
}
func (this *dbusPropertyTimedateCanNTP) GetType() reflect.Type {
	return reflect.TypeOf((*bool)(nil)).Elem()
}

type dbusPropertyTimedateNTP struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyTimedateNTP) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Timedate.NTP is not writable")
}

func (this *dbusPropertyTimedateNTP) Get() bool {
	v, _ := this.GetValue()
	return v.(bool)
}
func (this *dbusPropertyTimedateNTP) GetValue() (interface{} /*bool*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "com.deepin.daemon.Timedate", "NTP").Store(&r)
	if err == nil && r.Signature().String() == "b" {
		return r.Value().(bool), nil
	}
	return *new(bool), err
}
func (this *dbusPropertyTimedateNTP) GetType() reflect.Type {
	return reflect.TypeOf((*bool)(nil)).Elem()
}

type dbusPropertyTimedateLocalRTC struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyTimedateLocalRTC) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Timedate.LocalRTC is not writable")
}

func (this *dbusPropertyTimedateLocalRTC) Get() bool {
	v, _ := this.GetValue()
	return v.(bool)
}
func (this *dbusPropertyTimedateLocalRTC) GetValue() (interface{} /*bool*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "com.deepin.daemon.Timedate", "LocalRTC").Store(&r)
	if err == nil && r.Signature().String() == "b" {
		return r.Value().(bool), nil
	}
	return *new(bool), err
}
func (this *dbusPropertyTimedateLocalRTC) GetType() reflect.Type {
	return reflect.TypeOf((*bool)(nil)).Elem()
}

type dbusPropertyTimedateTimezone struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyTimedateTimezone) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Timedate.Timezone is not writable")
}

func (this *dbusPropertyTimedateTimezone) Get() string {
	v, _ := this.GetValue()
	return v.(string)
}
func (this *dbusPropertyTimedateTimezone) GetValue() (interface{} /*string*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "com.deepin.daemon.Timedate", "Timezone").Store(&r)
	if err == nil && r.Signature().String() == "s" {
		return r.Value().(string), nil
	}
	return *new(string), err
}
func (this *dbusPropertyTimedateTimezone) GetType() reflect.Type {
	return reflect.TypeOf((*string)(nil)).Elem()
}

type dbusPropertyTimedateUse24HourFormat struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyTimedateUse24HourFormat) SetValue(v interface{} /*bool*/) {
	if reflect.TypeOf(v) == reflect.TypeOf((*bool)(nil)).Elem() {
		this.core.Call("org.freedesktop.DBus.Properties.Set", 0, "com.deepin.daemon.Timedate", "Use24HourFormat", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property Use24HourFormat of com.deepin.daemon.Timedate is an bool but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyTimedateUse24HourFormat) Set(v bool) {
	this.SetValue(v)
}

func (this *dbusPropertyTimedateUse24HourFormat) Get() bool {
	v, _ := this.GetValue()
	return v.(bool)
}
func (this *dbusPropertyTimedateUse24HourFormat) GetValue() (interface{} /*bool*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "com.deepin.daemon.Timedate", "Use24HourFormat").Store(&r)
	if err == nil && r.Signature().String() == "b" {
		return r.Value().(bool), nil
	}
	return *new(bool), err
}
func (this *dbusPropertyTimedateUse24HourFormat) GetType() reflect.Type {
	return reflect.TypeOf((*bool)(nil)).Elem()
}

type dbusPropertyTimedateDSTOffset struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyTimedateDSTOffset) SetValue(v interface{} /*int32*/) {
	if reflect.TypeOf(v) == reflect.TypeOf((*int32)(nil)).Elem() {
		this.core.Call("org.freedesktop.DBus.Properties.Set", 0, "com.deepin.daemon.Timedate", "DSTOffset", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property DSTOffset of com.deepin.daemon.Timedate is an int32 but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyTimedateDSTOffset) Set(v int32) {
	this.SetValue(v)
}

func (this *dbusPropertyTimedateDSTOffset) Get() int32 {
	v, _ := this.GetValue()
	return v.(int32)
}
func (this *dbusPropertyTimedateDSTOffset) GetValue() (interface{} /*int32*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "com.deepin.daemon.Timedate", "DSTOffset").Store(&r)
	if err == nil && r.Signature().String() == "i" {
		return r.Value().(int32), nil
	}
	return *new(int32), err
}
func (this *dbusPropertyTimedateDSTOffset) GetType() reflect.Type {
	return reflect.TypeOf((*int32)(nil)).Elem()
}

type dbusPropertyTimedateUserTimezones struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyTimedateUserTimezones) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Timedate.UserTimezones is not writable")
}

func (this *dbusPropertyTimedateUserTimezones) Get() []string {
	v, _ := this.GetValue()
	return v.([]string)
}
func (this *dbusPropertyTimedateUserTimezones) GetValue() (interface{} /*[]string*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "com.deepin.daemon.Timedate", "UserTimezones").Store(&r)
	if err == nil && r.Signature().String() == "as" {
		return r.Value().([]string), nil
	}
	return *new([]string), err
}
func (this *dbusPropertyTimedateUserTimezones) GetType() reflect.Type {
	return reflect.TypeOf((*[]string)(nil)).Elem()
}

func NewTimedate(destName string, path dbus.ObjectPath) (*Timedate, error) {
	if !path.IsValid() {
		return nil, errors.New("The path of '" + string(path) + "' is invalid.")
	}

	core := getBus().Object(destName, path)

	obj := &Timedate{Path: path, DestName: destName, core: core, signals: make(map[<-chan *dbus.Signal]struct{})}

	obj.CanNTP = &dbusPropertyTimedateCanNTP{&property.BaseObserver{}, core}
	obj.NTP = &dbusPropertyTimedateNTP{&property.BaseObserver{}, core}
	obj.LocalRTC = &dbusPropertyTimedateLocalRTC{&property.BaseObserver{}, core}
	obj.Timezone = &dbusPropertyTimedateTimezone{&property.BaseObserver{}, core}
	obj.Use24HourFormat = &dbusPropertyTimedateUse24HourFormat{&property.BaseObserver{}, core}
	obj.DSTOffset = &dbusPropertyTimedateDSTOffset{&property.BaseObserver{}, core}
	obj.UserTimezones = &dbusPropertyTimedateUserTimezones{&property.BaseObserver{}, core}

	dbusAddMatch("type='signal',path='" + string(path) + "',interface='org.freedesktop.DBus.Properties',sender='" + destName + "',member='PropertiesChanged'")
	dbusAddMatch("type='signal',path='" + string(path) + "',interface='com.deepin.daemon.Timedate',sender='" + destName + "',member='PropertiesChanged'")
	sigChan := obj._createSignalChan()
	go func() {
		typeString := reflect.TypeOf("")
		typeKeyValues := reflect.TypeOf(map[string]dbus.Variant{})
		typeArrayValues := reflect.TypeOf([]string{})
		for v := range sigChan {
			if v.Name == "org.freedesktop.DBus.Properties.PropertiesChanged" &&
				len(v.Body) == 3 &&
				reflect.TypeOf(v.Body[0]) == typeString &&
				reflect.TypeOf(v.Body[1]) == typeKeyValues &&
				reflect.TypeOf(v.Body[2]) == typeArrayValues &&
				v.Body[0].(string) == "com.deepin.daemon.Timedate" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "CanNTP" {
						obj.CanNTP.Notify()

					} else if key == "NTP" {
						obj.NTP.Notify()

					} else if key == "LocalRTC" {
						obj.LocalRTC.Notify()

					} else if key == "Timezone" {
						obj.Timezone.Notify()

					} else if key == "Use24HourFormat" {
						obj.Use24HourFormat.Notify()

					} else if key == "DSTOffset" {
						obj.DSTOffset.Notify()

					} else if key == "UserTimezones" {
						obj.UserTimezones.Notify()
					}
				}
			} else if v.Name == "com.deepin.daemon.Timedate.PropertiesChanged" && len(v.Body) == 1 && reflect.TypeOf(v.Body[0]) == typeKeyValues {
				for key, _ := range v.Body[0].(map[string]dbus.Variant) {
					if false {
					} else if key == "CanNTP" {
						obj.CanNTP.Notify()

					} else if key == "NTP" {
						obj.NTP.Notify()

					} else if key == "LocalRTC" {
						obj.LocalRTC.Notify()

					} else if key == "Timezone" {
						obj.Timezone.Notify()

					} else if key == "Use24HourFormat" {
						obj.Use24HourFormat.Notify()

					} else if key == "DSTOffset" {
						obj.DSTOffset.Notify()

					} else if key == "UserTimezones" {
						obj.UserTimezones.Notify()
					}
				}
			}
		}
	}()

	runtime.SetFinalizer(obj, func(_obj *Timedate) { DestroyTimedate(_obj) })
	return obj, nil
}
