// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdjson"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdp"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tgerr"
)

// No-op definition for keeping imports.
var (
	_ = bin.Buffer{}
	_ = context.Background()
	_ = fmt.Stringer(nil)
	_ = strings.Builder{}
	_ = errors.Is
	_ = multierr.AppendInto
	_ = sort.Ints
	_ = tdp.Format
	_ = tgerr.Error{}
	_ = tdjson.Encoder{}
)

// MessagesReportMusicListenRequest represents TL type `messages.reportMusicListen#ddbcd819`.
//
// See https://core.telegram.org/method/messages.reportMusicListen for reference.
type MessagesReportMusicListenRequest struct {
	// ID field of MessagesReportMusicListenRequest.
	ID InputDocumentClass
	// ListenedDuration field of MessagesReportMusicListenRequest.
	ListenedDuration int
}

// MessagesReportMusicListenRequestTypeID is TL type id of MessagesReportMusicListenRequest.
const MessagesReportMusicListenRequestTypeID = 0xddbcd819

// Ensuring interfaces in compile-time for MessagesReportMusicListenRequest.
var (
	_ bin.Encoder     = &MessagesReportMusicListenRequest{}
	_ bin.Decoder     = &MessagesReportMusicListenRequest{}
	_ bin.BareEncoder = &MessagesReportMusicListenRequest{}
	_ bin.BareDecoder = &MessagesReportMusicListenRequest{}
)

func (r *MessagesReportMusicListenRequest) Zero() bool {
	if r == nil {
		return true
	}
	if !(r.ID == nil) {
		return false
	}
	if !(r.ListenedDuration == 0) {
		return false
	}

	return true
}

// String implements fmt.Stringer.
func (r *MessagesReportMusicListenRequest) String() string {
	if r == nil {
		return "MessagesReportMusicListenRequest(nil)"
	}
	type Alias MessagesReportMusicListenRequest
	return fmt.Sprintf("MessagesReportMusicListenRequest%+v", Alias(*r))
}

// FillFrom fills MessagesReportMusicListenRequest from given interface.
func (r *MessagesReportMusicListenRequest) FillFrom(from interface {
	GetID() (value InputDocumentClass)
	GetListenedDuration() (value int)
}) {
	r.ID = from.GetID()
	r.ListenedDuration = from.GetListenedDuration()
}

// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*MessagesReportMusicListenRequest) TypeID() uint32 {
	return MessagesReportMusicListenRequestTypeID
}

// TypeName returns name of type in TL schema.
func (*MessagesReportMusicListenRequest) TypeName() string {
	return "messages.reportMusicListen"
}

// TypeInfo returns info about TL type.
func (r *MessagesReportMusicListenRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.reportMusicListen",
		ID:   MessagesReportMusicListenRequestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "ListenedDuration",
			SchemaName: "listened_duration",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (r *MessagesReportMusicListenRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode messages.reportMusicListen#ddbcd819 as nil")
	}
	b.PutID(MessagesReportMusicListenRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *MessagesReportMusicListenRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode messages.reportMusicListen#ddbcd819 as nil")
	}
	if r.ID == nil {
		return fmt.Errorf("unable to encode messages.reportMusicListen#ddbcd819: field id is nil")
	}
	if err := r.ID.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messages.reportMusicListen#ddbcd819: field id: %w", err)
	}
	b.PutInt(r.ListenedDuration)
	return nil
}

// Decode implements bin.Decoder.
func (r *MessagesReportMusicListenRequest) Decode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode messages.reportMusicListen#ddbcd819 to nil")
	}
	if err := b.ConsumeID(MessagesReportMusicListenRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.reportMusicListen#ddbcd819: %w", err)
	}
	return r.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (r *MessagesReportMusicListenRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode messages.reportMusicListen#ddbcd819 to nil")
	}
	{
		value, err := DecodeInputDocument(b)
		if err != nil {
			return fmt.Errorf("unable to decode messages.reportMusicListen#ddbcd819: field id: %w", err)
		}
		r.ID = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messages.reportMusicListen#ddbcd819: field listened_duration: %w", err)
		}
		r.ListenedDuration = value
	}
	return nil
}

// GetID returns value of ID field.
func (r *MessagesReportMusicListenRequest) GetID() (value InputDocumentClass) {
	if r == nil {
		return
	}
	return r.ID
}

// GetListenedDuration returns value of ListenedDuration field.
func (r *MessagesReportMusicListenRequest) GetListenedDuration() (value int) {
	if r == nil {
		return
	}
	return r.ListenedDuration
}

// GetIDAsNotEmpty returns mapped value of ID field.
func (r *MessagesReportMusicListenRequest) GetIDAsNotEmpty() (*InputDocument, bool) {
	return r.ID.AsNotEmpty()
}

// MessagesReportMusicListen invokes method messages.reportMusicListen#ddbcd819 returning error if any.
//
// See https://core.telegram.org/method/messages.reportMusicListen for reference.
func (c *Client) MessagesReportMusicListen(ctx context.Context, request *MessagesReportMusicListenRequest) (bool, error) {
	var result BoolBox

	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return false, err
	}
	_, ok := result.Bool.(*BoolTrue)
	return ok, nil
}
