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

// ToggleSupergroupHasAutomaticTranslationRequest represents TL type `toggleSupergroupHasAutomaticTranslation#f4f93ae8`.
type ToggleSupergroupHasAutomaticTranslationRequest struct {
	// The identifier of the channel
	SupergroupID int64
	// The new value of has_automatic_translation
	HasAutomaticTranslation bool
}

// ToggleSupergroupHasAutomaticTranslationRequestTypeID is TL type id of ToggleSupergroupHasAutomaticTranslationRequest.
const ToggleSupergroupHasAutomaticTranslationRequestTypeID = 0xf4f93ae8

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

func (t *ToggleSupergroupHasAutomaticTranslationRequest) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.SupergroupID == 0) {
		return false
	}
	if !(t.HasAutomaticTranslation == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *ToggleSupergroupHasAutomaticTranslationRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "toggleSupergroupHasAutomaticTranslation",
		ID:   ToggleSupergroupHasAutomaticTranslationRequestTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "SupergroupID",
			SchemaName: "supergroup_id",
		},
		{
			Name:       "HasAutomaticTranslation",
			SchemaName: "has_automatic_translation",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *ToggleSupergroupHasAutomaticTranslationRequest) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleSupergroupHasAutomaticTranslation#f4f93ae8 as nil")
	}
	b.PutID(ToggleSupergroupHasAutomaticTranslationRequestTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *ToggleSupergroupHasAutomaticTranslationRequest) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleSupergroupHasAutomaticTranslation#f4f93ae8 as nil")
	}
	b.PutInt53(t.SupergroupID)
	b.PutBool(t.HasAutomaticTranslation)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (t *ToggleSupergroupHasAutomaticTranslationRequest) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode toggleSupergroupHasAutomaticTranslation#f4f93ae8 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode toggleSupergroupHasAutomaticTranslation#f4f93ae8: field supergroup_id: %w", err)
		}
		t.SupergroupID = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode toggleSupergroupHasAutomaticTranslation#f4f93ae8: field has_automatic_translation: %w", err)
		}
		t.HasAutomaticTranslation = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (t *ToggleSupergroupHasAutomaticTranslationRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleSupergroupHasAutomaticTranslation#f4f93ae8 as nil")
	}
	b.ObjStart()
	b.PutID("toggleSupergroupHasAutomaticTranslation")
	b.Comma()
	b.FieldStart("supergroup_id")
	b.PutInt53(t.SupergroupID)
	b.Comma()
	b.FieldStart("has_automatic_translation")
	b.PutBool(t.HasAutomaticTranslation)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("toggleSupergroupHasAutomaticTranslation"); err != nil {
				return fmt.Errorf("unable to decode toggleSupergroupHasAutomaticTranslation#f4f93ae8: %w", err)
			}
		case "supergroup_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode toggleSupergroupHasAutomaticTranslation#f4f93ae8: field supergroup_id: %w", err)
			}
			t.SupergroupID = value
		case "has_automatic_translation":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode toggleSupergroupHasAutomaticTranslation#f4f93ae8: field has_automatic_translation: %w", err)
			}
			t.HasAutomaticTranslation = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetSupergroupID returns value of SupergroupID field.
func (t *ToggleSupergroupHasAutomaticTranslationRequest) GetSupergroupID() (value int64) {
	if t == nil {
		return
	}
	return t.SupergroupID
}

// GetHasAutomaticTranslation returns value of HasAutomaticTranslation field.
func (t *ToggleSupergroupHasAutomaticTranslationRequest) GetHasAutomaticTranslation() (value bool) {
	if t == nil {
		return
	}
	return t.HasAutomaticTranslation
}

// ToggleSupergroupHasAutomaticTranslation invokes method toggleSupergroupHasAutomaticTranslation#f4f93ae8 returning error if any.
func (c *Client) ToggleSupergroupHasAutomaticTranslation(ctx context.Context, request *ToggleSupergroupHasAutomaticTranslationRequest) error {
	var ok Ok

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