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

// PaymentsGetStarGiftAuctionStateRequest represents TL type `payments.getStarGiftAuctionState#5c9ff4d6`.
//
// See https://core.telegram.org/method/payments.getStarGiftAuctionState for reference.
type PaymentsGetStarGiftAuctionStateRequest struct {
	// Auction field of PaymentsGetStarGiftAuctionStateRequest.
	Auction InputStarGiftAuctionClass
	// Version field of PaymentsGetStarGiftAuctionStateRequest.
	Version int
}

// PaymentsGetStarGiftAuctionStateRequestTypeID is TL type id of PaymentsGetStarGiftAuctionStateRequest.
const PaymentsGetStarGiftAuctionStateRequestTypeID = 0x5c9ff4d6

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

func (g *PaymentsGetStarGiftAuctionStateRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Auction == nil) {
		return false
	}
	if !(g.Version == 0) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsGetStarGiftAuctionStateRequest from given interface.
func (g *PaymentsGetStarGiftAuctionStateRequest) FillFrom(from interface {
	GetAuction() (value InputStarGiftAuctionClass)
	GetVersion() (value int)
}) {
	g.Auction = from.GetAuction()
	g.Version = from.GetVersion()
}

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

// TypeName returns name of type in TL schema.
func (*PaymentsGetStarGiftAuctionStateRequest) TypeName() string {
	return "payments.getStarGiftAuctionState"
}

// TypeInfo returns info about TL type.
func (g *PaymentsGetStarGiftAuctionStateRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "payments.getStarGiftAuctionState",
		ID:   PaymentsGetStarGiftAuctionStateRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Auction",
			SchemaName: "auction",
		},
		{
			Name:       "Version",
			SchemaName: "version",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *PaymentsGetStarGiftAuctionStateRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode payments.getStarGiftAuctionState#5c9ff4d6 as nil")
	}
	b.PutID(PaymentsGetStarGiftAuctionStateRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *PaymentsGetStarGiftAuctionStateRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode payments.getStarGiftAuctionState#5c9ff4d6 as nil")
	}
	if g.Auction == nil {
		return fmt.Errorf("unable to encode payments.getStarGiftAuctionState#5c9ff4d6: field auction is nil")
	}
	if err := g.Auction.Encode(b); err != nil {
		return fmt.Errorf("unable to encode payments.getStarGiftAuctionState#5c9ff4d6: field auction: %w", err)
	}
	b.PutInt(g.Version)
	return nil
}

// Decode implements bin.Decoder.
func (g *PaymentsGetStarGiftAuctionStateRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode payments.getStarGiftAuctionState#5c9ff4d6 to nil")
	}
	if err := b.ConsumeID(PaymentsGetStarGiftAuctionStateRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode payments.getStarGiftAuctionState#5c9ff4d6: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *PaymentsGetStarGiftAuctionStateRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode payments.getStarGiftAuctionState#5c9ff4d6 to nil")
	}
	{
		value, err := DecodeInputStarGiftAuction(b)
		if err != nil {
			return fmt.Errorf("unable to decode payments.getStarGiftAuctionState#5c9ff4d6: field auction: %w", err)
		}
		g.Auction = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode payments.getStarGiftAuctionState#5c9ff4d6: field version: %w", err)
		}
		g.Version = value
	}
	return nil
}

// GetAuction returns value of Auction field.
func (g *PaymentsGetStarGiftAuctionStateRequest) GetAuction() (value InputStarGiftAuctionClass) {
	if g == nil {
		return
	}
	return g.Auction
}

// GetVersion returns value of Version field.
func (g *PaymentsGetStarGiftAuctionStateRequest) GetVersion() (value int) {
	if g == nil {
		return
	}
	return g.Version
}

// PaymentsGetStarGiftAuctionState invokes method payments.getStarGiftAuctionState#5c9ff4d6 returning error if any.
//
// See https://core.telegram.org/method/payments.getStarGiftAuctionState for reference.
func (c *Client) PaymentsGetStarGiftAuctionState(ctx context.Context, request *PaymentsGetStarGiftAuctionStateRequest) (*PaymentsStarGiftAuctionState, error) {
	var result PaymentsStarGiftAuctionState

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