// Generated by go-wayland-scanner
// https://github.com/yaslama/go-wayland/cmd/go-wayland-scanner
// XML file : internal/proto/xml/ext-data-control-v1.xml
//
// ext_data_control_v1 Protocol Copyright:
//
// Copyright © 2018 Simon Ser
// Copyright © 2019 Ivan Molodetskikh
// Copyright © 2024 Neal Gompa
//
// Permission to use, copy, modify, distribute, and sell this
// software and its documentation for any purpose is hereby granted
// without fee, provided that the above copyright notice appear in
// all copies and that both that copyright notice and this permission
// notice appear in supporting documentation, and that the name of
// the copyright holders not be used in advertising or publicity
// pertaining to distribution of the software without specific,
// written prior permission.  The copyright holders make no
// representations about the suitability of this software for any
// purpose.  It is provided "as is" without express or implied
// warranty.
//
// THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
// SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
// THIS SOFTWARE.

package ext_data_control

import (
	"github.com/AvengeMedia/DankMaterialShell/core/pkg/go-wayland/wayland/client"
	"golang.org/x/sys/unix"
)

// ExtDataControlManagerV1InterfaceName is the name of the interface as it appears in the [client.Registry].
// It can be used to match the [client.RegistryGlobalEvent.Interface] in the
// [Registry.SetGlobalHandler] and can be used in [Registry.Bind] if this applies.
const ExtDataControlManagerV1InterfaceName = "ext_data_control_manager_v1"

// ExtDataControlManagerV1 : manager to control data devices
//
// This interface is a manager that allows creating per-seat data device
// controls.
type ExtDataControlManagerV1 struct {
	client.BaseProxy
}

// NewExtDataControlManagerV1 : manager to control data devices
//
// This interface is a manager that allows creating per-seat data device
// controls.
func NewExtDataControlManagerV1(ctx *client.Context) *ExtDataControlManagerV1 {
	extDataControlManagerV1 := &ExtDataControlManagerV1{}
	ctx.Register(extDataControlManagerV1)
	return extDataControlManagerV1
}

// CreateDataSource : create a new data source
//
// Create a new data source.
func (i *ExtDataControlManagerV1) CreateDataSource() (*ExtDataControlSourceV1, error) {
	id := NewExtDataControlSourceV1(i.Context())
	const opcode = 0
	const _reqBufLen = 8 + 4
	var _reqBuf [_reqBufLen]byte
	l := 0
	client.PutUint32(_reqBuf[l:4], i.ID())
	l += 4
	client.PutUint32(_reqBuf[l:l+4], uint32(_reqBufLen<<16|opcode&0x0000ffff))
	l += 4
	client.PutUint32(_reqBuf[l:l+4], id.ID())
	l += 4
	err := i.Context().WriteMsg(_reqBuf[:], nil)
	return id, err
}

// GetDataDevice : get a data device for a seat
//
// Create a data device that can be used to manage a seat's selection.
func (i *ExtDataControlManagerV1) GetDataDevice(seat *client.Seat) (*ExtDataControlDeviceV1, error) {
	id := NewExtDataControlDeviceV1(i.Context())
	const opcode = 1
	const _reqBufLen = 8 + 4 + 4
	var _reqBuf [_reqBufLen]byte
	l := 0
	client.PutUint32(_reqBuf[l:4], i.ID())
	l += 4
	client.PutUint32(_reqBuf[l:l+4], uint32(_reqBufLen<<16|opcode&0x0000ffff))
	l += 4
	client.PutUint32(_reqBuf[l:l+4], id.ID())
	l += 4
	client.PutUint32(_reqBuf[l:l+4], seat.ID())
	l += 4
	err := i.Context().WriteMsg(_reqBuf[:], nil)
	return id, err
}

// GetDataDeviceWithProxy : get a data device for a seat using a pre-created proxy
//
// Like GetDataDevice, but uses a pre-created ExtDataControlDeviceV1 proxy.
// This allows setting up event handlers before the request is sent.
func (i *ExtDataControlManagerV1) GetDataDeviceWithProxy(device *ExtDataControlDeviceV1, seat *client.Seat) error {
	const opcode = 1
	const _reqBufLen = 8 + 4 + 4
	var _reqBuf [_reqBufLen]byte
	l := 0
	client.PutUint32(_reqBuf[l:4], i.ID())
	l += 4
	client.PutUint32(_reqBuf[l:l+4], uint32(_reqBufLen<<16|opcode&0x0000ffff))
	l += 4
	client.PutUint32(_reqBuf[l:l+4], device.ID())
	l += 4
	client.PutUint32(_reqBuf[l:l+4], seat.ID())
	l += 4
	return i.Context().WriteMsg(_reqBuf[:], nil)
}

// Destroy : destroy the manager
//
// All objects created by the manager will still remain valid, until their
// appropriate destroy request has been called.
func (i *ExtDataControlManagerV1) Destroy() error {
	defer i.MarkZombie()
	const opcode = 2
	const _reqBufLen = 8
	var _reqBuf [_reqBufLen]byte
	l := 0
	client.PutUint32(_reqBuf[l:4], i.ID())
	l += 4
	client.PutUint32(_reqBuf[l:l+4], uint32(_reqBufLen<<16|opcode&0x0000ffff))
	l += 4
	err := i.Context().WriteMsg(_reqBuf[:], nil)
	return err
}

// ExtDataControlDeviceV1InterfaceName is the name of the interface as it appears in the [client.Registry].
// It can be used to match the [client.RegistryGlobalEvent.Interface] in the
// [Registry.SetGlobalHandler] and can be used in [Registry.Bind] if this applies.
const ExtDataControlDeviceV1InterfaceName = "ext_data_control_device_v1"

// ExtDataControlDeviceV1 : manage a data device for a seat
//
// This interface allows a client to manage a seat's selection.
//
// When the seat is destroyed, this object becomes inert.
type ExtDataControlDeviceV1 struct {
	client.BaseProxy
	dataOfferHandler        ExtDataControlDeviceV1DataOfferHandlerFunc
	selectionHandler        ExtDataControlDeviceV1SelectionHandlerFunc
	finishedHandler         ExtDataControlDeviceV1FinishedHandlerFunc
	primarySelectionHandler ExtDataControlDeviceV1PrimarySelectionHandlerFunc
}

// NewExtDataControlDeviceV1 : manage a data device for a seat
//
// This interface allows a client to manage a seat's selection.
//
// When the seat is destroyed, this object becomes inert.
func NewExtDataControlDeviceV1(ctx *client.Context) *ExtDataControlDeviceV1 {
	extDataControlDeviceV1 := &ExtDataControlDeviceV1{}
	ctx.Register(extDataControlDeviceV1)
	return extDataControlDeviceV1
}

// SetSelection : copy data to the selection
//
// This request asks the compositor to set the selection to the data from
// the source on behalf of the client.
//
// The given source may not be used in any further set_selection or
// set_primary_selection requests. Attempting to use a previously used
// source triggers the used_source protocol error.
//
// To unset the selection, set the source to NULL.
func (i *ExtDataControlDeviceV1) SetSelection(source *ExtDataControlSourceV1) error {
	const opcode = 0
	const _reqBufLen = 8 + 4
	var _reqBuf [_reqBufLen]byte
	l := 0
	client.PutUint32(_reqBuf[l:4], i.ID())
	l += 4
	client.PutUint32(_reqBuf[l:l+4], uint32(_reqBufLen<<16|opcode&0x0000ffff))
	l += 4
	if source == nil {
		client.PutUint32(_reqBuf[l:l+4], 0)
		l += 4
	} else {
		client.PutUint32(_reqBuf[l:l+4], source.ID())
		l += 4
	}
	err := i.Context().WriteMsg(_reqBuf[:], nil)
	return err
}

// Destroy : destroy this data device
//
// Destroys the data device object.
func (i *ExtDataControlDeviceV1) Destroy() error {
	defer i.MarkZombie()
	const opcode = 1
	const _reqBufLen = 8
	var _reqBuf [_reqBufLen]byte
	l := 0
	client.PutUint32(_reqBuf[l:4], i.ID())
	l += 4
	client.PutUint32(_reqBuf[l:l+4], uint32(_reqBufLen<<16|opcode&0x0000ffff))
	l += 4
	err := i.Context().WriteMsg(_reqBuf[:], nil)
	return err
}

// SetPrimarySelection : copy data to the primary selection
//
// This request asks the compositor to set the primary selection to the
// data from the source on behalf of the client.
//
// The given source may not be used in any further set_selection or
// set_primary_selection requests. Attempting to use a previously used
// source triggers the used_source protocol error.
//
// To unset the primary selection, set the source to NULL.
//
// The compositor will ignore this request if it does not support primary
// selection.
func (i *ExtDataControlDeviceV1) SetPrimarySelection(source *ExtDataControlSourceV1) error {
	const opcode = 2
	const _reqBufLen = 8 + 4
	var _reqBuf [_reqBufLen]byte
	l := 0
	client.PutUint32(_reqBuf[l:4], i.ID())
	l += 4
	client.PutUint32(_reqBuf[l:l+4], uint32(_reqBufLen<<16|opcode&0x0000ffff))
	l += 4
	if source == nil {
		client.PutUint32(_reqBuf[l:l+4], 0)
		l += 4
	} else {
		client.PutUint32(_reqBuf[l:l+4], source.ID())
		l += 4
	}
	err := i.Context().WriteMsg(_reqBuf[:], nil)
	return err
}

type ExtDataControlDeviceV1Error uint32

// ExtDataControlDeviceV1Error :
const (
	// ExtDataControlDeviceV1ErrorUsedSource : source given to set_selection or set_primary_selection was already used before
	ExtDataControlDeviceV1ErrorUsedSource ExtDataControlDeviceV1Error = 1
)

func (e ExtDataControlDeviceV1Error) Name() string {
	switch e {
	case ExtDataControlDeviceV1ErrorUsedSource:
		return "used_source"
	default:
		return ""
	}
}

func (e ExtDataControlDeviceV1Error) Value() string {
	switch e {
	case ExtDataControlDeviceV1ErrorUsedSource:
		return "1"
	default:
		return ""
	}
}

func (e ExtDataControlDeviceV1Error) String() string {
	return e.Name() + "=" + e.Value()
}

// ExtDataControlDeviceV1DataOfferEvent : introduce a new ext_data_control_offer
//
// The data_offer event introduces a new ext_data_control_offer object,
// which will subsequently be used in either the
// ext_data_control_device.selection event (for the regular clipboard
// selections) or the ext_data_control_device.primary_selection event (for
// the primary clipboard selections). Immediately following the
// ext_data_control_device.data_offer event, the new data_offer object
// will send out ext_data_control_offer.offer events to describe the MIME
// types it offers.
type ExtDataControlDeviceV1DataOfferEvent struct {
	Id *ExtDataControlOfferV1
}
type ExtDataControlDeviceV1DataOfferHandlerFunc func(ExtDataControlDeviceV1DataOfferEvent)

// SetDataOfferHandler : sets handler for ExtDataControlDeviceV1DataOfferEvent
func (i *ExtDataControlDeviceV1) SetDataOfferHandler(f ExtDataControlDeviceV1DataOfferHandlerFunc) {
	i.dataOfferHandler = f
}

// ExtDataControlDeviceV1SelectionEvent : advertise new selection
//
// The selection event is sent out to notify the client of a new
// ext_data_control_offer for the selection for this device. The
// ext_data_control_device.data_offer and the ext_data_control_offer.offer
// events are sent out immediately before this event to introduce the data
// offer object. The selection event is sent to a client when a new
// selection is set. The ext_data_control_offer is valid until a new
// ext_data_control_offer or NULL is received. The client must destroy the
// previous selection ext_data_control_offer, if any, upon receiving this
// event. Regardless, the previous selection will be ignored once a new
// selection ext_data_control_offer is received.
//
// The first selection event is sent upon binding the
// ext_data_control_device object.
type ExtDataControlDeviceV1SelectionEvent struct {
	Id      *ExtDataControlOfferV1
	OfferId uint32 // Raw object ID for external registry lookups
}
type ExtDataControlDeviceV1SelectionHandlerFunc func(ExtDataControlDeviceV1SelectionEvent)

// SetSelectionHandler : sets handler for ExtDataControlDeviceV1SelectionEvent
func (i *ExtDataControlDeviceV1) SetSelectionHandler(f ExtDataControlDeviceV1SelectionHandlerFunc) {
	i.selectionHandler = f
}

// ExtDataControlDeviceV1FinishedEvent : this data control is no longer valid
//
// This data control object is no longer valid and should be destroyed by
// the client.
type ExtDataControlDeviceV1FinishedEvent struct{}
type ExtDataControlDeviceV1FinishedHandlerFunc func(ExtDataControlDeviceV1FinishedEvent)

// SetFinishedHandler : sets handler for ExtDataControlDeviceV1FinishedEvent
func (i *ExtDataControlDeviceV1) SetFinishedHandler(f ExtDataControlDeviceV1FinishedHandlerFunc) {
	i.finishedHandler = f
}

// ExtDataControlDeviceV1PrimarySelectionEvent : advertise new primary selection
//
// The primary_selection event is sent out to notify the client of a new
// ext_data_control_offer for the primary selection for this device. The
// ext_data_control_device.data_offer and the ext_data_control_offer.offer
// events are sent out immediately before this event to introduce the data
// offer object. The primary_selection event is sent to a client when a
// new primary selection is set. The ext_data_control_offer is valid until
// a new ext_data_control_offer or NULL is received. The client must
// destroy the previous primary selection ext_data_control_offer, if any,
// upon receiving this event. Regardless, the previous primary selection
// will be ignored once a new primary selection ext_data_control_offer is
// received.
//
// If the compositor supports primary selection, the first
// primary_selection event is sent upon binding the
// ext_data_control_device object.
type ExtDataControlDeviceV1PrimarySelectionEvent struct {
	Id      *ExtDataControlOfferV1
	OfferId uint32 // Raw object ID for external registry lookups
}
type ExtDataControlDeviceV1PrimarySelectionHandlerFunc func(ExtDataControlDeviceV1PrimarySelectionEvent)

// SetPrimarySelectionHandler : sets handler for ExtDataControlDeviceV1PrimarySelectionEvent
func (i *ExtDataControlDeviceV1) SetPrimarySelectionHandler(f ExtDataControlDeviceV1PrimarySelectionHandlerFunc) {
	i.primarySelectionHandler = f
}

func (i *ExtDataControlDeviceV1) Dispatch(opcode uint32, fd int, data []byte) {
	switch opcode {
	case 0:
		// data_offer event: server creates a new object (new_id)
		if i.dataOfferHandler == nil {
			return
		}
		var e ExtDataControlDeviceV1DataOfferEvent
		l := 0
		newID := client.Uint32(data[l : l+4])
		l += 4

		ctx := i.Context()
		offer := &ExtDataControlOfferV1{}
		offer.SetContext(ctx)
		offer.SetID(newID)
		ctx.RegisterWithID(offer, newID)
		e.Id = offer

		i.dataOfferHandler(e)
	case 1:
		// selection event: nullable object reference
		if i.selectionHandler == nil {
			return
		}
		var e ExtDataControlDeviceV1SelectionEvent
		l := 0
		objID := client.Uint32(data[l : l+4])
		l += 4

		e.OfferId = objID
		if objID != 0 {
			if p := i.Context().GetProxy(objID); p != nil {
				e.Id = p.(*ExtDataControlOfferV1)
			}
		}

		i.selectionHandler(e)
	case 2:
		if i.finishedHandler == nil {
			return
		}
		var e ExtDataControlDeviceV1FinishedEvent

		i.finishedHandler(e)
	case 3:
		// primary_selection event: nullable object reference
		if i.primarySelectionHandler == nil {
			return
		}
		var e ExtDataControlDeviceV1PrimarySelectionEvent
		l := 0
		objID := client.Uint32(data[l : l+4])
		l += 4

		e.OfferId = objID
		if objID != 0 {
			if p := i.Context().GetProxy(objID); p != nil {
				e.Id = p.(*ExtDataControlOfferV1)
			}
		}

		i.primarySelectionHandler(e)
	}
}

// ExtDataControlSourceV1InterfaceName is the name of the interface as it appears in the [client.Registry].
// It can be used to match the [client.RegistryGlobalEvent.Interface] in the
// [Registry.SetGlobalHandler] and can be used in [Registry.Bind] if this applies.
const ExtDataControlSourceV1InterfaceName = "ext_data_control_source_v1"

// ExtDataControlSourceV1 : offer to transfer data
//
// The ext_data_control_source object is the source side of a
// ext_data_control_offer. It is created by the source client in a data
// transfer and provides a way to describe the offered data and a way to
// respond to requests to transfer the data.
type ExtDataControlSourceV1 struct {
	client.BaseProxy
	sendHandler      ExtDataControlSourceV1SendHandlerFunc
	cancelledHandler ExtDataControlSourceV1CancelledHandlerFunc
}

// NewExtDataControlSourceV1 : offer to transfer data
//
// The ext_data_control_source object is the source side of a
// ext_data_control_offer. It is created by the source client in a data
// transfer and provides a way to describe the offered data and a way to
// respond to requests to transfer the data.
func NewExtDataControlSourceV1(ctx *client.Context) *ExtDataControlSourceV1 {
	extDataControlSourceV1 := &ExtDataControlSourceV1{}
	ctx.Register(extDataControlSourceV1)
	return extDataControlSourceV1
}

// Offer : add an offered MIME type
//
// This request adds a MIME type to the set of MIME types advertised to
// targets. Can be called several times to offer multiple types.
//
// Calling this after ext_data_control_device.set_selection is a protocol
// error.
//
//	mimeType: MIME type offered by the data source
func (i *ExtDataControlSourceV1) Offer(mimeType string) error {
	const opcode = 0
	mimeTypeLen := client.PaddedLen(len(mimeType) + 1)
	_reqBufLen := 8 + (4 + mimeTypeLen)
	_reqBuf := make([]byte, _reqBufLen)
	l := 0
	client.PutUint32(_reqBuf[l:4], i.ID())
	l += 4
	client.PutUint32(_reqBuf[l:l+4], uint32(_reqBufLen<<16|opcode&0x0000ffff))
	l += 4
	client.PutString(_reqBuf[l:l+(4+mimeTypeLen)], mimeType)
	l += (4 + mimeTypeLen)
	err := i.Context().WriteMsg(_reqBuf, nil)
	return err
}

// Destroy : destroy this source
//
// Destroys the data source object.
func (i *ExtDataControlSourceV1) Destroy() error {
	defer i.MarkZombie()
	const opcode = 1
	const _reqBufLen = 8
	var _reqBuf [_reqBufLen]byte
	l := 0
	client.PutUint32(_reqBuf[l:4], i.ID())
	l += 4
	client.PutUint32(_reqBuf[l:l+4], uint32(_reqBufLen<<16|opcode&0x0000ffff))
	l += 4
	err := i.Context().WriteMsg(_reqBuf[:], nil)
	return err
}

type ExtDataControlSourceV1Error uint32

// ExtDataControlSourceV1Error :
const (
	// ExtDataControlSourceV1ErrorInvalidOffer : offer sent after ext_data_control_device.set_selection
	ExtDataControlSourceV1ErrorInvalidOffer ExtDataControlSourceV1Error = 1
)

func (e ExtDataControlSourceV1Error) Name() string {
	switch e {
	case ExtDataControlSourceV1ErrorInvalidOffer:
		return "invalid_offer"
	default:
		return ""
	}
}

func (e ExtDataControlSourceV1Error) Value() string {
	switch e {
	case ExtDataControlSourceV1ErrorInvalidOffer:
		return "1"
	default:
		return ""
	}
}

func (e ExtDataControlSourceV1Error) String() string {
	return e.Name() + "=" + e.Value()
}

// ExtDataControlSourceV1SendEvent : send the data
//
// Request for data from the client. Send the data as the specified MIME
// type over the passed file descriptor, then close it.
type ExtDataControlSourceV1SendEvent struct {
	MimeType string
	Fd       int
}
type ExtDataControlSourceV1SendHandlerFunc func(ExtDataControlSourceV1SendEvent)

// SetSendHandler : sets handler for ExtDataControlSourceV1SendEvent
func (i *ExtDataControlSourceV1) SetSendHandler(f ExtDataControlSourceV1SendHandlerFunc) {
	i.sendHandler = f
}

// ExtDataControlSourceV1CancelledEvent : selection was cancelled
//
// This data source is no longer valid. The data source has been replaced
// by another data source.
//
// The client should clean up and destroy this data source.
type ExtDataControlSourceV1CancelledEvent struct{}
type ExtDataControlSourceV1CancelledHandlerFunc func(ExtDataControlSourceV1CancelledEvent)

// SetCancelledHandler : sets handler for ExtDataControlSourceV1CancelledEvent
func (i *ExtDataControlSourceV1) SetCancelledHandler(f ExtDataControlSourceV1CancelledHandlerFunc) {
	i.cancelledHandler = f
}

func (i *ExtDataControlSourceV1) Dispatch(opcode uint32, fd int, data []byte) {
	switch opcode {
	case 0:
		if i.sendHandler == nil {
			if fd != -1 {
				unix.Close(fd)
			}
			return
		}
		var e ExtDataControlSourceV1SendEvent
		l := 0
		mimeTypeLen := client.PaddedLen(int(client.Uint32(data[l : l+4])))
		l += 4
		e.MimeType = client.String(data[l : l+mimeTypeLen])
		l += mimeTypeLen
		e.Fd = fd

		i.sendHandler(e)
	case 1:
		if i.cancelledHandler == nil {
			return
		}
		var e ExtDataControlSourceV1CancelledEvent

		i.cancelledHandler(e)
	}
}

// ExtDataControlOfferV1InterfaceName is the name of the interface as it appears in the [client.Registry].
// It can be used to match the [client.RegistryGlobalEvent.Interface] in the
// [Registry.SetGlobalHandler] and can be used in [Registry.Bind] if this applies.
const ExtDataControlOfferV1InterfaceName = "ext_data_control_offer_v1"

// ExtDataControlOfferV1 : offer to transfer data
//
// A ext_data_control_offer represents a piece of data offered for transfer
// by another client (the source client). The offer describes the different
// MIME types that the data can be converted to and provides the mechanism
// for transferring the data directly from the source client.
type ExtDataControlOfferV1 struct {
	client.BaseProxy
	offerHandler ExtDataControlOfferV1OfferHandlerFunc
}

// NewExtDataControlOfferV1 : offer to transfer data
//
// A ext_data_control_offer represents a piece of data offered for transfer
// by another client (the source client). The offer describes the different
// MIME types that the data can be converted to and provides the mechanism
// for transferring the data directly from the source client.
func NewExtDataControlOfferV1(ctx *client.Context) *ExtDataControlOfferV1 {
	extDataControlOfferV1 := &ExtDataControlOfferV1{}
	ctx.Register(extDataControlOfferV1)
	return extDataControlOfferV1
}

// Receive : request that the data is transferred
//
// To transfer the offered data, the client issues this request and
// indicates the MIME type it wants to receive. The transfer happens
// through the passed file descriptor (typically created with the pipe
// system call). The source client writes the data in the MIME type
// representation requested and then closes the file descriptor.
//
// The receiving client reads from the read end of the pipe until EOF and
// then closes its end, at which point the transfer is complete.
//
// This request may happen multiple times for different MIME types.
//
//	mimeType: MIME type desired by receiver
//	fd: file descriptor for data transfer
func (i *ExtDataControlOfferV1) Receive(mimeType string, fd int) error {
	const opcode = 0
	mimeTypeLen := client.PaddedLen(len(mimeType) + 1)
	_reqBufLen := 8 + (4 + mimeTypeLen)
	_reqBuf := make([]byte, _reqBufLen)
	l := 0
	client.PutUint32(_reqBuf[l:4], i.ID())
	l += 4
	client.PutUint32(_reqBuf[l:l+4], uint32(_reqBufLen<<16|opcode&0x0000ffff))
	l += 4
	client.PutString(_reqBuf[l:l+(4+mimeTypeLen)], mimeType)
	l += (4 + mimeTypeLen)
	oob := unix.UnixRights(int(fd))
	err := i.Context().WriteMsg(_reqBuf, oob)
	return err
}

// Destroy : destroy this offer
//
// Destroys the data offer object.
func (i *ExtDataControlOfferV1) Destroy() error {
	defer i.MarkZombie()
	const opcode = 1
	const _reqBufLen = 8
	var _reqBuf [_reqBufLen]byte
	l := 0
	client.PutUint32(_reqBuf[l:4], i.ID())
	l += 4
	client.PutUint32(_reqBuf[l:l+4], uint32(_reqBufLen<<16|opcode&0x0000ffff))
	l += 4
	err := i.Context().WriteMsg(_reqBuf[:], nil)
	return err
}

// ExtDataControlOfferV1OfferEvent : advertise offered MIME type
//
// Sent immediately after creating the ext_data_control_offer object.
// One event per offered MIME type.
type ExtDataControlOfferV1OfferEvent struct {
	MimeType string
}
type ExtDataControlOfferV1OfferHandlerFunc func(ExtDataControlOfferV1OfferEvent)

// SetOfferHandler : sets handler for ExtDataControlOfferV1OfferEvent
func (i *ExtDataControlOfferV1) SetOfferHandler(f ExtDataControlOfferV1OfferHandlerFunc) {
	i.offerHandler = f
}

func (i *ExtDataControlOfferV1) Dispatch(opcode uint32, fd int, data []byte) {
	switch opcode {
	case 0:
		if i.offerHandler == nil {
			return
		}
		var e ExtDataControlOfferV1OfferEvent
		l := 0
		mimeTypeLen := client.PaddedLen(int(client.Uint32(data[l : l+4])))
		l += 4
		e.MimeType = client.String(data[l : l+mimeTypeLen])
		l += mimeTypeLen

		i.offerHandler(e)
	}
}
