// 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/foundation/collections"
	"github.com/go-ole/go-ole"
)

const SignatureGattLocalService string = "rc(Windows.Devices.Bluetooth.GenericAttributeProfile.GattLocalService;{f513e258-f7f7-4902-b803-57fcc7d6fe83})"

type GattLocalService struct {
	ole.IUnknown
}

func (impl *GattLocalService) GetUuid() (syscall.GUID, error) {
	itf := impl.MustQueryInterface(ole.NewGUID(GUIDiGattLocalService))
	defer itf.Release()
	v := (*iGattLocalService)(unsafe.Pointer(itf))
	return v.GetUuid()
}

func (impl *GattLocalService) CreateCharacteristicAsync(characteristicUuid syscall.GUID, parameters *GattLocalCharacteristicParameters) (*foundation.IAsyncOperation, error) {
	itf := impl.MustQueryInterface(ole.NewGUID(GUIDiGattLocalService))
	defer itf.Release()
	v := (*iGattLocalService)(unsafe.Pointer(itf))
	return v.CreateCharacteristicAsync(characteristicUuid, parameters)
}

func (impl *GattLocalService) GetCharacteristics() (*collections.IVectorView, error) {
	itf := impl.MustQueryInterface(ole.NewGUID(GUIDiGattLocalService))
	defer itf.Release()
	v := (*iGattLocalService)(unsafe.Pointer(itf))
	return v.GetCharacteristics()
}

const GUIDiGattLocalService string = "f513e258-f7f7-4902-b803-57fcc7d6fe83"
const SignatureiGattLocalService string = "{f513e258-f7f7-4902-b803-57fcc7d6fe83}"

type iGattLocalService struct {
	ole.IInspectable
}

type iGattLocalServiceVtbl struct {
	ole.IInspectableVtbl

	GetUuid                   uintptr
	CreateCharacteristicAsync uintptr
	GetCharacteristics        uintptr
}

func (v *iGattLocalService) VTable() *iGattLocalServiceVtbl {
	return (*iGattLocalServiceVtbl)(unsafe.Pointer(v.RawVTable))
}

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

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

	return out, nil
}

func (v *iGattLocalService) CreateCharacteristicAsync(characteristicUuid syscall.GUID, parameters *GattLocalCharacteristicParameters) (*foundation.IAsyncOperation, error) {
	var out *foundation.IAsyncOperation
	hr, _, _ := syscall.SyscallN(
		v.VTable().CreateCharacteristicAsync,
		uintptr(unsafe.Pointer(v)),                   // this
		uintptr(unsafe.Pointer(&characteristicUuid)), // in syscall.GUID
		uintptr(unsafe.Pointer(parameters)),          // in GattLocalCharacteristicParameters
		uintptr(unsafe.Pointer(&out)),                // out foundation.IAsyncOperation
	)

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

	return out, nil
}

func (v *iGattLocalService) GetCharacteristics() (*collections.IVectorView, error) {
	var out *collections.IVectorView
	hr, _, _ := syscall.SyscallN(
		v.VTable().GetCharacteristics,
		uintptr(unsafe.Pointer(v)),    // this
		uintptr(unsafe.Pointer(&out)), // out collections.IVectorView
	)

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

	return out, nil
}
