// Code generated by winrt-go-gen. DO NOT EDIT.

//go:build windows

//nolint:all
package genericattributeprofile

import (
	"syscall"
	"unsafe"

	"git.savin.nyc/alex/go-winrt/windows/foundation"
	"git.savin.nyc/alex/go-winrt/windows/storage/streams"
	"github.com/go-ole/go-ole"
)

const SignatureGattWriteRequest string = "rc(Windows.Devices.Bluetooth.GenericAttributeProfile.GattWriteRequest;{aeb6a9ed-de2f-4fc2-a9a8-94ea7844f13d})"

type GattWriteRequest struct {
	ole.IUnknown
}

func (impl *GattWriteRequest) GetValue() (*streams.IBuffer, error) {
	itf := impl.MustQueryInterface(ole.NewGUID(GUIDiGattWriteRequest))
	defer itf.Release()
	v := (*iGattWriteRequest)(unsafe.Pointer(itf))
	return v.GetValue()
}

func (impl *GattWriteRequest) GetOffset() (uint32, error) {
	itf := impl.MustQueryInterface(ole.NewGUID(GUIDiGattWriteRequest))
	defer itf.Release()
	v := (*iGattWriteRequest)(unsafe.Pointer(itf))
	return v.GetOffset()
}

func (impl *GattWriteRequest) GetOption() (GattWriteOption, error) {
	itf := impl.MustQueryInterface(ole.NewGUID(GUIDiGattWriteRequest))
	defer itf.Release()
	v := (*iGattWriteRequest)(unsafe.Pointer(itf))
	return v.GetOption()
}

func (impl *GattWriteRequest) GetState() (GattRequestState, error) {
	itf := impl.MustQueryInterface(ole.NewGUID(GUIDiGattWriteRequest))
	defer itf.Release()
	v := (*iGattWriteRequest)(unsafe.Pointer(itf))
	return v.GetState()
}

func (impl *GattWriteRequest) AddStateChanged(handler *foundation.TypedEventHandler) (foundation.EventRegistrationToken, error) {
	itf := impl.MustQueryInterface(ole.NewGUID(GUIDiGattWriteRequest))
	defer itf.Release()
	v := (*iGattWriteRequest)(unsafe.Pointer(itf))
	return v.AddStateChanged(handler)
}

func (impl *GattWriteRequest) RemoveStateChanged(token foundation.EventRegistrationToken) error {
	itf := impl.MustQueryInterface(ole.NewGUID(GUIDiGattWriteRequest))
	defer itf.Release()
	v := (*iGattWriteRequest)(unsafe.Pointer(itf))
	return v.RemoveStateChanged(token)
}

func (impl *GattWriteRequest) Respond() error {
	itf := impl.MustQueryInterface(ole.NewGUID(GUIDiGattWriteRequest))
	defer itf.Release()
	v := (*iGattWriteRequest)(unsafe.Pointer(itf))
	return v.Respond()
}

func (impl *GattWriteRequest) RespondWithProtocolError(protocolError uint8) error {
	itf := impl.MustQueryInterface(ole.NewGUID(GUIDiGattWriteRequest))
	defer itf.Release()
	v := (*iGattWriteRequest)(unsafe.Pointer(itf))
	return v.RespondWithProtocolError(protocolError)
}

const GUIDiGattWriteRequest string = "aeb6a9ed-de2f-4fc2-a9a8-94ea7844f13d"
const SignatureiGattWriteRequest string = "{aeb6a9ed-de2f-4fc2-a9a8-94ea7844f13d}"

type iGattWriteRequest struct {
	ole.IInspectable
}

type iGattWriteRequestVtbl struct {
	ole.IInspectableVtbl

	GetValue                 uintptr
	GetOffset                uintptr
	GetOption                uintptr
	GetState                 uintptr
	AddStateChanged          uintptr
	RemoveStateChanged       uintptr
	Respond                  uintptr
	RespondWithProtocolError uintptr
}

func (v *iGattWriteRequest) VTable() *iGattWriteRequestVtbl {
	return (*iGattWriteRequestVtbl)(unsafe.Pointer(v.RawVTable))
}

func (v *iGattWriteRequest) GetValue() (*streams.IBuffer, error) {
	var out *streams.IBuffer
	hr, _, _ := syscall.SyscallN(
		v.VTable().GetValue,
		uintptr(unsafe.Pointer(v)),    // this
		uintptr(unsafe.Pointer(&out)), // out streams.IBuffer
	)

	if hr != 0 {
		return nil, ole.NewError(hr)
	}

	return out, nil
}

func (v *iGattWriteRequest) GetOffset() (uint32, error) {
	var out uint32
	hr, _, _ := syscall.SyscallN(
		v.VTable().GetOffset,
		uintptr(unsafe.Pointer(v)),    // this
		uintptr(unsafe.Pointer(&out)), // out uint32
	)

	if hr != 0 {
		return 0, ole.NewError(hr)
	}

	return out, nil
}

func (v *iGattWriteRequest) GetOption() (GattWriteOption, error) {
	var out GattWriteOption
	hr, _, _ := syscall.SyscallN(
		v.VTable().GetOption,
		uintptr(unsafe.Pointer(v)),    // this
		uintptr(unsafe.Pointer(&out)), // out GattWriteOption
	)

	if hr != 0 {
		return GattWriteOptionWriteWithResponse, ole.NewError(hr)
	}

	return out, nil
}

func (v *iGattWriteRequest) GetState() (GattRequestState, error) {
	var out GattRequestState
	hr, _, _ := syscall.SyscallN(
		v.VTable().GetState,
		uintptr(unsafe.Pointer(v)),    // this
		uintptr(unsafe.Pointer(&out)), // out GattRequestState
	)

	if hr != 0 {
		return GattRequestStatePending, ole.NewError(hr)
	}

	return out, nil
}

func (v *iGattWriteRequest) AddStateChanged(handler *foundation.TypedEventHandler) (foundation.EventRegistrationToken, error) {
	var out foundation.EventRegistrationToken
	hr, _, _ := syscall.SyscallN(
		v.VTable().AddStateChanged,
		uintptr(unsafe.Pointer(v)),       // this
		uintptr(unsafe.Pointer(handler)), // in foundation.TypedEventHandler
		uintptr(unsafe.Pointer(&out)),    // out foundation.EventRegistrationToken
	)

	if hr != 0 {
		return foundation.EventRegistrationToken{}, ole.NewError(hr)
	}

	return out, nil
}

func (v *iGattWriteRequest) RemoveStateChanged(token foundation.EventRegistrationToken) error {
	hr, _, _ := syscall.SyscallN(
		v.VTable().RemoveStateChanged,
		uintptr(unsafe.Pointer(v)),      // this
		uintptr(unsafe.Pointer(&token)), // in foundation.EventRegistrationToken
	)

	if hr != 0 {
		return ole.NewError(hr)
	}

	return nil
}

func (v *iGattWriteRequest) Respond() error {
	hr, _, _ := syscall.SyscallN(
		v.VTable().Respond,
		uintptr(unsafe.Pointer(v)), // this
	)

	if hr != 0 {
		return ole.NewError(hr)
	}

	return nil
}

func (v *iGattWriteRequest) RespondWithProtocolError(protocolError uint8) error {
	hr, _, _ := syscall.SyscallN(
		v.VTable().RespondWithProtocolError,
		uintptr(unsafe.Pointer(v)), // this
		uintptr(protocolError),     // in uint8
	)

	if hr != 0 {
		return ole.NewError(hr)
	}

	return nil
}
