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

// AddCustomServerLanguagePackRequest represents TL type `addCustomServerLanguagePack#448de3`.
type AddCustomServerLanguagePackRequest struct {
	// Identifier of a language pack to be added
	LanguagePackID string
}

// AddCustomServerLanguagePackRequestTypeID is TL type id of AddCustomServerLanguagePackRequest.
const AddCustomServerLanguagePackRequestTypeID = 0x448de3

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

func (a *AddCustomServerLanguagePackRequest) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.LanguagePackID == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (a *AddCustomServerLanguagePackRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "addCustomServerLanguagePack",
		ID:   AddCustomServerLanguagePackRequestTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "LanguagePackID",
			SchemaName: "language_pack_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *AddCustomServerLanguagePackRequest) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode addCustomServerLanguagePack#448de3 as nil")
	}
	b.PutID(AddCustomServerLanguagePackRequestTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *AddCustomServerLanguagePackRequest) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode addCustomServerLanguagePack#448de3 as nil")
	}
	b.PutString(a.LanguagePackID)
	return nil
}

// Decode implements bin.Decoder.
func (a *AddCustomServerLanguagePackRequest) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode addCustomServerLanguagePack#448de3 to nil")
	}
	if err := b.ConsumeID(AddCustomServerLanguagePackRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode addCustomServerLanguagePack#448de3: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *AddCustomServerLanguagePackRequest) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode addCustomServerLanguagePack#448de3 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode addCustomServerLanguagePack#448de3: field language_pack_id: %w", err)
		}
		a.LanguagePackID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (a *AddCustomServerLanguagePackRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if a == nil {
		return fmt.Errorf("can't encode addCustomServerLanguagePack#448de3 as nil")
	}
	b.ObjStart()
	b.PutID("addCustomServerLanguagePack")
	b.Comma()
	b.FieldStart("language_pack_id")
	b.PutString(a.LanguagePackID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (a *AddCustomServerLanguagePackRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if a == nil {
		return fmt.Errorf("can't decode addCustomServerLanguagePack#448de3 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("addCustomServerLanguagePack"); err != nil {
				return fmt.Errorf("unable to decode addCustomServerLanguagePack#448de3: %w", err)
			}
		case "language_pack_id":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode addCustomServerLanguagePack#448de3: field language_pack_id: %w", err)
			}
			a.LanguagePackID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetLanguagePackID returns value of LanguagePackID field.
func (a *AddCustomServerLanguagePackRequest) GetLanguagePackID() (value string) {
	if a == nil {
		return
	}
	return a.LanguagePackID
}

// AddCustomServerLanguagePack invokes method addCustomServerLanguagePack#448de3 returning error if any.
func (c *Client) AddCustomServerLanguagePack(ctx context.Context, languagepackid string) error {
	var ok Ok

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