// Code generated by gotdgen, DO NOT EDIT.

package tdapi

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

// GetUpgradedGiftWithdrawalURLRequest represents TL type `getUpgradedGiftWithdrawalUrl#d1400e4c`.
type GetUpgradedGiftWithdrawalURLRequest struct {
	// Identifier of the gift
	ReceivedGiftID string
	// The 2-step verification password of the current user
	Password string
}

// GetUpgradedGiftWithdrawalURLRequestTypeID is TL type id of GetUpgradedGiftWithdrawalURLRequest.
const GetUpgradedGiftWithdrawalURLRequestTypeID = 0xd1400e4c

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

func (g *GetUpgradedGiftWithdrawalURLRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.ReceivedGiftID == "") {
		return false
	}
	if !(g.Password == "") {
		return false
	}

	return true
}

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

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

// TypeName returns name of type in TL schema.
func (*GetUpgradedGiftWithdrawalURLRequest) TypeName() string {
	return "getUpgradedGiftWithdrawalUrl"
}

// TypeInfo returns info about TL type.
func (g *GetUpgradedGiftWithdrawalURLRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getUpgradedGiftWithdrawalUrl",
		ID:   GetUpgradedGiftWithdrawalURLRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ReceivedGiftID",
			SchemaName: "received_gift_id",
		},
		{
			Name:       "Password",
			SchemaName: "password",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetUpgradedGiftWithdrawalURLRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getUpgradedGiftWithdrawalUrl#d1400e4c as nil")
	}
	b.PutID(GetUpgradedGiftWithdrawalURLRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetUpgradedGiftWithdrawalURLRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getUpgradedGiftWithdrawalUrl#d1400e4c as nil")
	}
	b.PutString(g.ReceivedGiftID)
	b.PutString(g.Password)
	return nil
}

// Decode implements bin.Decoder.
func (g *GetUpgradedGiftWithdrawalURLRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getUpgradedGiftWithdrawalUrl#d1400e4c to nil")
	}
	if err := b.ConsumeID(GetUpgradedGiftWithdrawalURLRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode getUpgradedGiftWithdrawalUrl#d1400e4c: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *GetUpgradedGiftWithdrawalURLRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getUpgradedGiftWithdrawalUrl#d1400e4c to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode getUpgradedGiftWithdrawalUrl#d1400e4c: field received_gift_id: %w", err)
		}
		g.ReceivedGiftID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode getUpgradedGiftWithdrawalUrl#d1400e4c: field password: %w", err)
		}
		g.Password = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetUpgradedGiftWithdrawalURLRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getUpgradedGiftWithdrawalUrl#d1400e4c as nil")
	}
	b.ObjStart()
	b.PutID("getUpgradedGiftWithdrawalUrl")
	b.Comma()
	b.FieldStart("received_gift_id")
	b.PutString(g.ReceivedGiftID)
	b.Comma()
	b.FieldStart("password")
	b.PutString(g.Password)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (g *GetUpgradedGiftWithdrawalURLRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if g == nil {
		return fmt.Errorf("can't decode getUpgradedGiftWithdrawalUrl#d1400e4c to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("getUpgradedGiftWithdrawalUrl"); err != nil {
				return fmt.Errorf("unable to decode getUpgradedGiftWithdrawalUrl#d1400e4c: %w", err)
			}
		case "received_gift_id":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode getUpgradedGiftWithdrawalUrl#d1400e4c: field received_gift_id: %w", err)
			}
			g.ReceivedGiftID = value
		case "password":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode getUpgradedGiftWithdrawalUrl#d1400e4c: field password: %w", err)
			}
			g.Password = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetReceivedGiftID returns value of ReceivedGiftID field.
func (g *GetUpgradedGiftWithdrawalURLRequest) GetReceivedGiftID() (value string) {
	if g == nil {
		return
	}
	return g.ReceivedGiftID
}

// GetPassword returns value of Password field.
func (g *GetUpgradedGiftWithdrawalURLRequest) GetPassword() (value string) {
	if g == nil {
		return
	}
	return g.Password
}

// GetUpgradedGiftWithdrawalURL invokes method getUpgradedGiftWithdrawalUrl#d1400e4c returning error if any.
func (c *Client) GetUpgradedGiftWithdrawalURL(ctx context.Context, request *GetUpgradedGiftWithdrawalURLRequest) (*HTTPURL, error) {
	var result HTTPURL

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