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

// GetPassportAuthorizationFormAvailableElementsRequest represents TL type `getPassportAuthorizationFormAvailableElements#3fb314fc`.
type GetPassportAuthorizationFormAvailableElementsRequest struct {
	// Authorization form identifier
	AuthorizationFormID int32
	// The 2-step verification password of the current user
	Password string
}

// GetPassportAuthorizationFormAvailableElementsRequestTypeID is TL type id of GetPassportAuthorizationFormAvailableElementsRequest.
const GetPassportAuthorizationFormAvailableElementsRequestTypeID = 0x3fb314fc

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

func (g *GetPassportAuthorizationFormAvailableElementsRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.AuthorizationFormID == 0) {
		return false
	}
	if !(g.Password == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GetPassportAuthorizationFormAvailableElementsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getPassportAuthorizationFormAvailableElements",
		ID:   GetPassportAuthorizationFormAvailableElementsRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "AuthorizationFormID",
			SchemaName: "authorization_form_id",
		},
		{
			Name:       "Password",
			SchemaName: "password",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetPassportAuthorizationFormAvailableElementsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getPassportAuthorizationFormAvailableElements#3fb314fc as nil")
	}
	b.PutID(GetPassportAuthorizationFormAvailableElementsRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetPassportAuthorizationFormAvailableElementsRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getPassportAuthorizationFormAvailableElements#3fb314fc as nil")
	}
	b.PutInt32(g.AuthorizationFormID)
	b.PutString(g.Password)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *GetPassportAuthorizationFormAvailableElementsRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getPassportAuthorizationFormAvailableElements#3fb314fc to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode getPassportAuthorizationFormAvailableElements#3fb314fc: field authorization_form_id: %w", err)
		}
		g.AuthorizationFormID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode getPassportAuthorizationFormAvailableElements#3fb314fc: field password: %w", err)
		}
		g.Password = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetPassportAuthorizationFormAvailableElementsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getPassportAuthorizationFormAvailableElements#3fb314fc as nil")
	}
	b.ObjStart()
	b.PutID("getPassportAuthorizationFormAvailableElements")
	b.Comma()
	b.FieldStart("authorization_form_id")
	b.PutInt32(g.AuthorizationFormID)
	b.Comma()
	b.FieldStart("password")
	b.PutString(g.Password)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

// GetAuthorizationFormID returns value of AuthorizationFormID field.
func (g *GetPassportAuthorizationFormAvailableElementsRequest) GetAuthorizationFormID() (value int32) {
	if g == nil {
		return
	}
	return g.AuthorizationFormID
}

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

// GetPassportAuthorizationFormAvailableElements invokes method getPassportAuthorizationFormAvailableElements#3fb314fc returning error if any.
func (c *Client) GetPassportAuthorizationFormAvailableElements(ctx context.Context, request *GetPassportAuthorizationFormAvailableElementsRequest) (*PassportElementsWithErrors, error) {
	var result PassportElementsWithErrors

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