// 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{}
)

// PhoneDeclineConferenceCallInviteRequest represents TL type `phone.declineConferenceCallInvite#3c479971`.
// Declines a conference call invite.
//
// See https://core.telegram.org/method/phone.declineConferenceCallInvite for reference.
type PhoneDeclineConferenceCallInviteRequest struct {
	// The ID of the messageActionConferenceCall¹ to decline.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/messageActionConferenceCall
	MsgID int
}

// PhoneDeclineConferenceCallInviteRequestTypeID is TL type id of PhoneDeclineConferenceCallInviteRequest.
const PhoneDeclineConferenceCallInviteRequestTypeID = 0x3c479971

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

func (d *PhoneDeclineConferenceCallInviteRequest) Zero() bool {
	if d == nil {
		return true
	}
	if !(d.MsgID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills PhoneDeclineConferenceCallInviteRequest from given interface.
func (d *PhoneDeclineConferenceCallInviteRequest) FillFrom(from interface {
	GetMsgID() (value int)
}) {
	d.MsgID = from.GetMsgID()
}

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

// TypeName returns name of type in TL schema.
func (*PhoneDeclineConferenceCallInviteRequest) TypeName() string {
	return "phone.declineConferenceCallInvite"
}

// TypeInfo returns info about TL type.
func (d *PhoneDeclineConferenceCallInviteRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "phone.declineConferenceCallInvite",
		ID:   PhoneDeclineConferenceCallInviteRequestTypeID,
	}
	if d == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "MsgID",
			SchemaName: "msg_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (d *PhoneDeclineConferenceCallInviteRequest) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode phone.declineConferenceCallInvite#3c479971 as nil")
	}
	b.PutID(PhoneDeclineConferenceCallInviteRequestTypeID)
	return d.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (d *PhoneDeclineConferenceCallInviteRequest) EncodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode phone.declineConferenceCallInvite#3c479971 as nil")
	}
	b.PutInt(d.MsgID)
	return nil
}

// Decode implements bin.Decoder.
func (d *PhoneDeclineConferenceCallInviteRequest) Decode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode phone.declineConferenceCallInvite#3c479971 to nil")
	}
	if err := b.ConsumeID(PhoneDeclineConferenceCallInviteRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode phone.declineConferenceCallInvite#3c479971: %w", err)
	}
	return d.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (d *PhoneDeclineConferenceCallInviteRequest) DecodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode phone.declineConferenceCallInvite#3c479971 to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode phone.declineConferenceCallInvite#3c479971: field msg_id: %w", err)
		}
		d.MsgID = value
	}
	return nil
}

// GetMsgID returns value of MsgID field.
func (d *PhoneDeclineConferenceCallInviteRequest) GetMsgID() (value int) {
	if d == nil {
		return
	}
	return d.MsgID
}

// PhoneDeclineConferenceCallInvite invokes method phone.declineConferenceCallInvite#3c479971 returning error if any.
// Declines a conference call invite.
//
// Possible errors:
//
//	400 MESSAGE_ID_INVALID: The provided message id is invalid.
//
// See https://core.telegram.org/method/phone.declineConferenceCallInvite for reference.
func (c *Client) PhoneDeclineConferenceCallInvite(ctx context.Context, msgid int) (UpdatesClass, error) {
	var result UpdatesBox

	request := &PhoneDeclineConferenceCallInviteRequest{
		MsgID: msgid,
	}
	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return nil, err
	}
	return result.Updates, nil
}
