// 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 SignatureGattReadRequest string = "rc(Windows.Devices.Bluetooth.GenericAttributeProfile.GattReadRequest;{f1dd6535-6acd-42a6-a4bb-d789dae0043e})"

type GattReadRequest struct {
	ole.IUnknown
}

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

func (impl *GattReadRequest) GetLength() (uint32, error) {
	itf := impl.MustQueryInterface(ole.NewGUID(GUIDiGattReadRequest))
	defer itf.Release()
	v := (*iGattReadRequest)(unsafe.Pointer(itf))
	return v.GetLength()
}

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

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

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

func (impl *GattReadRequest) RespondWithValue(value *streams.IBuffer) error {
	itf := impl.MustQueryInterface(ole.NewGUID(GUIDiGattReadRequest))
	defer itf.Release()
	v := (*iGattReadRequest)(unsafe.Pointer(itf))
	return v.RespondWithValue(value)
}

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

const GUIDiGattReadRequest string = "f1dd6535-6acd-42a6-a4bb-d789dae0043e"
const SignatureiGattReadRequest string = "{f1dd6535-6acd-42a6-a4bb-d789dae0043e}"

type iGattReadRequest struct {
	ole.IInspectable
}

type iGattReadRequestVtbl struct {
	ole.IInspectableVtbl

	GetOffset                uintptr
	GetLength                uintptr
	GetState                 uintptr
	AddStateChanged          uintptr
	RemoveStateChanged       uintptr
	RespondWithValue         uintptr
	RespondWithProtocolError uintptr
}

func (v *iGattReadRequest) VTable() *iGattReadRequestVtbl {
	return (*iGattReadRequestVtbl)(unsafe.Pointer(v.RawVTable))
}

func (v *iGattReadRequest) 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 *iGattReadRequest) GetLength() (uint32, error) {
	var out uint32
	hr, _, _ := syscall.SyscallN(
		v.VTable().GetLength,
		uintptr(unsafe.Pointer(v)),    // this
		uintptr(unsafe.Pointer(&out)), // out uint32
	)

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

	return out, nil
}

func (v *iGattReadRequest) 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 *iGattReadRequest) 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 *iGattReadRequest) 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 *iGattReadRequest) RespondWithValue(value *streams.IBuffer) error {
	hr, _, _ := syscall.SyscallN(
		v.VTable().RespondWithValue,
		uintptr(unsafe.Pointer(v)),     // this
		uintptr(unsafe.Pointer(value)), // in streams.IBuffer
	)

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

	return nil
}

func (v *iGattReadRequest) 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
}
