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

// ToggleSupergroupHasHiddenMembersRequest represents TL type `toggleSupergroupHasHiddenMembers#a4559dca`.
type ToggleSupergroupHasHiddenMembersRequest struct {
	// Identifier of the supergroup
	SupergroupID int64
	// New value of has_hidden_members
	HasHiddenMembers bool
}

// ToggleSupergroupHasHiddenMembersRequestTypeID is TL type id of ToggleSupergroupHasHiddenMembersRequest.
const ToggleSupergroupHasHiddenMembersRequestTypeID = 0xa4559dca

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

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (t *ToggleSupergroupHasHiddenMembersRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "toggleSupergroupHasHiddenMembers",
		ID:   ToggleSupergroupHasHiddenMembersRequestTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "SupergroupID",
			SchemaName: "supergroup_id",
		},
		{
			Name:       "HasHiddenMembers",
			SchemaName: "has_hidden_members",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *ToggleSupergroupHasHiddenMembersRequest) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleSupergroupHasHiddenMembers#a4559dca as nil")
	}
	b.PutID(ToggleSupergroupHasHiddenMembersRequestTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *ToggleSupergroupHasHiddenMembersRequest) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleSupergroupHasHiddenMembers#a4559dca as nil")
	}
	b.PutInt53(t.SupergroupID)
	b.PutBool(t.HasHiddenMembers)
	return nil
}

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

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

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (t *ToggleSupergroupHasHiddenMembersRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if t == nil {
		return fmt.Errorf("can't encode toggleSupergroupHasHiddenMembers#a4559dca as nil")
	}
	b.ObjStart()
	b.PutID("toggleSupergroupHasHiddenMembers")
	b.Comma()
	b.FieldStart("supergroup_id")
	b.PutInt53(t.SupergroupID)
	b.Comma()
	b.FieldStart("has_hidden_members")
	b.PutBool(t.HasHiddenMembers)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

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

// GetHasHiddenMembers returns value of HasHiddenMembers field.
func (t *ToggleSupergroupHasHiddenMembersRequest) GetHasHiddenMembers() (value bool) {
	if t == nil {
		return
	}
	return t.HasHiddenMembers
}

// ToggleSupergroupHasHiddenMembers invokes method toggleSupergroupHasHiddenMembers#a4559dca returning error if any.
func (c *Client) ToggleSupergroupHasHiddenMembers(ctx context.Context, request *ToggleSupergroupHasHiddenMembersRequest) error {
	var ok Ok

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