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

// AccountAddNoPaidMessagesExceptionRequest represents TL type `account.addNoPaidMessagesException#6f688aa7`.
//
// See https://core.telegram.org/method/account.addNoPaidMessagesException for reference.
type AccountAddNoPaidMessagesExceptionRequest struct {
	// Flags field of AccountAddNoPaidMessagesExceptionRequest.
	Flags bin.Fields
	// RefundCharged field of AccountAddNoPaidMessagesExceptionRequest.
	RefundCharged bool
	// UserID field of AccountAddNoPaidMessagesExceptionRequest.
	UserID InputUserClass
}

// AccountAddNoPaidMessagesExceptionRequestTypeID is TL type id of AccountAddNoPaidMessagesExceptionRequest.
const AccountAddNoPaidMessagesExceptionRequestTypeID = 0x6f688aa7

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

func (a *AccountAddNoPaidMessagesExceptionRequest) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.Flags.Zero()) {
		return false
	}
	if !(a.RefundCharged == false) {
		return false
	}
	if !(a.UserID == nil) {
		return false
	}

	return true
}

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

// FillFrom fills AccountAddNoPaidMessagesExceptionRequest from given interface.
func (a *AccountAddNoPaidMessagesExceptionRequest) FillFrom(from interface {
	GetRefundCharged() (value bool)
	GetUserID() (value InputUserClass)
}) {
	a.RefundCharged = from.GetRefundCharged()
	a.UserID = from.GetUserID()
}

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

// TypeName returns name of type in TL schema.
func (*AccountAddNoPaidMessagesExceptionRequest) TypeName() string {
	return "account.addNoPaidMessagesException"
}

// TypeInfo returns info about TL type.
func (a *AccountAddNoPaidMessagesExceptionRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "account.addNoPaidMessagesException",
		ID:   AccountAddNoPaidMessagesExceptionRequestTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "RefundCharged",
			SchemaName: "refund_charged",
			Null:       !a.Flags.Has(0),
		},
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (a *AccountAddNoPaidMessagesExceptionRequest) SetFlags() {
	if !(a.RefundCharged == false) {
		a.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func (a *AccountAddNoPaidMessagesExceptionRequest) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode account.addNoPaidMessagesException#6f688aa7 as nil")
	}
	b.PutID(AccountAddNoPaidMessagesExceptionRequestTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *AccountAddNoPaidMessagesExceptionRequest) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode account.addNoPaidMessagesException#6f688aa7 as nil")
	}
	a.SetFlags()
	if err := a.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode account.addNoPaidMessagesException#6f688aa7: field flags: %w", err)
	}
	if a.UserID == nil {
		return fmt.Errorf("unable to encode account.addNoPaidMessagesException#6f688aa7: field user_id is nil")
	}
	if err := a.UserID.Encode(b); err != nil {
		return fmt.Errorf("unable to encode account.addNoPaidMessagesException#6f688aa7: field user_id: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (a *AccountAddNoPaidMessagesExceptionRequest) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode account.addNoPaidMessagesException#6f688aa7 to nil")
	}
	if err := b.ConsumeID(AccountAddNoPaidMessagesExceptionRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode account.addNoPaidMessagesException#6f688aa7: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *AccountAddNoPaidMessagesExceptionRequest) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode account.addNoPaidMessagesException#6f688aa7 to nil")
	}
	{
		if err := a.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode account.addNoPaidMessagesException#6f688aa7: field flags: %w", err)
		}
	}
	a.RefundCharged = a.Flags.Has(0)
	{
		value, err := DecodeInputUser(b)
		if err != nil {
			return fmt.Errorf("unable to decode account.addNoPaidMessagesException#6f688aa7: field user_id: %w", err)
		}
		a.UserID = value
	}
	return nil
}

// SetRefundCharged sets value of RefundCharged conditional field.
func (a *AccountAddNoPaidMessagesExceptionRequest) SetRefundCharged(value bool) {
	if value {
		a.Flags.Set(0)
		a.RefundCharged = true
	} else {
		a.Flags.Unset(0)
		a.RefundCharged = false
	}
}

// GetRefundCharged returns value of RefundCharged conditional field.
func (a *AccountAddNoPaidMessagesExceptionRequest) GetRefundCharged() (value bool) {
	if a == nil {
		return
	}
	return a.Flags.Has(0)
}

// GetUserID returns value of UserID field.
func (a *AccountAddNoPaidMessagesExceptionRequest) GetUserID() (value InputUserClass) {
	if a == nil {
		return
	}
	return a.UserID
}

// AccountAddNoPaidMessagesException invokes method account.addNoPaidMessagesException#6f688aa7 returning error if any.
//
// See https://core.telegram.org/method/account.addNoPaidMessagesException for reference.
func (c *Client) AccountAddNoPaidMessagesException(ctx context.Context, request *AccountAddNoPaidMessagesExceptionRequest) (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
}
