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

// DeleteLanguagePackRequest represents TL type `deleteLanguagePack#824edc3e`.
type DeleteLanguagePackRequest struct {
	// Identifier of the language pack to delete
	LanguagePackID string
}

// DeleteLanguagePackRequestTypeID is TL type id of DeleteLanguagePackRequest.
const DeleteLanguagePackRequestTypeID = 0x824edc3e

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

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (d *DeleteLanguagePackRequest) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteLanguagePack#824edc3e as nil")
	}
	b.PutID(DeleteLanguagePackRequestTypeID)
	return d.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (d *DeleteLanguagePackRequest) EncodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteLanguagePack#824edc3e as nil")
	}
	b.PutString(d.LanguagePackID)
	return nil
}

// Decode implements bin.Decoder.
func (d *DeleteLanguagePackRequest) Decode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode deleteLanguagePack#824edc3e to nil")
	}
	if err := b.ConsumeID(DeleteLanguagePackRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode deleteLanguagePack#824edc3e: %w", err)
	}
	return d.DecodeBare(b)
}

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

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (d *DeleteLanguagePackRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteLanguagePack#824edc3e as nil")
	}
	b.ObjStart()
	b.PutID("deleteLanguagePack")
	b.Comma()
	b.FieldStart("language_pack_id")
	b.PutString(d.LanguagePackID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (d *DeleteLanguagePackRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if d == nil {
		return fmt.Errorf("can't decode deleteLanguagePack#824edc3e to nil")
	}

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

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

// DeleteLanguagePack invokes method deleteLanguagePack#824edc3e returning error if any.
func (c *Client) DeleteLanguagePack(ctx context.Context, languagepackid string) error {
	var ok Ok

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