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

// SetDefaultChannelAdministratorRightsRequest represents TL type `setDefaultChannelAdministratorRights#f20d5e19`.
type SetDefaultChannelAdministratorRightsRequest struct {
	// Default administrator rights for adding the bot to channels; pass null to remove
	// default rights
	DefaultChannelAdministratorRights ChatAdministratorRights
}

// SetDefaultChannelAdministratorRightsRequestTypeID is TL type id of SetDefaultChannelAdministratorRightsRequest.
const SetDefaultChannelAdministratorRightsRequestTypeID = 0xf20d5e19

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

func (s *SetDefaultChannelAdministratorRightsRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.DefaultChannelAdministratorRights.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetDefaultChannelAdministratorRightsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setDefaultChannelAdministratorRights",
		ID:   SetDefaultChannelAdministratorRightsRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "DefaultChannelAdministratorRights",
			SchemaName: "default_channel_administrator_rights",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetDefaultChannelAdministratorRightsRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setDefaultChannelAdministratorRights#f20d5e19 as nil")
	}
	b.PutID(SetDefaultChannelAdministratorRightsRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetDefaultChannelAdministratorRightsRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setDefaultChannelAdministratorRights#f20d5e19 as nil")
	}
	if err := s.DefaultChannelAdministratorRights.Encode(b); err != nil {
		return fmt.Errorf("unable to encode setDefaultChannelAdministratorRights#f20d5e19: field default_channel_administrator_rights: %w", err)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *SetDefaultChannelAdministratorRightsRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setDefaultChannelAdministratorRights#f20d5e19 to nil")
	}
	{
		if err := s.DefaultChannelAdministratorRights.Decode(b); err != nil {
			return fmt.Errorf("unable to decode setDefaultChannelAdministratorRights#f20d5e19: field default_channel_administrator_rights: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetDefaultChannelAdministratorRightsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setDefaultChannelAdministratorRights#f20d5e19 as nil")
	}
	b.ObjStart()
	b.PutID("setDefaultChannelAdministratorRights")
	b.Comma()
	b.FieldStart("default_channel_administrator_rights")
	if err := s.DefaultChannelAdministratorRights.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode setDefaultChannelAdministratorRights#f20d5e19: field default_channel_administrator_rights: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setDefaultChannelAdministratorRights"); err != nil {
				return fmt.Errorf("unable to decode setDefaultChannelAdministratorRights#f20d5e19: %w", err)
			}
		case "default_channel_administrator_rights":
			if err := s.DefaultChannelAdministratorRights.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode setDefaultChannelAdministratorRights#f20d5e19: field default_channel_administrator_rights: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetDefaultChannelAdministratorRights returns value of DefaultChannelAdministratorRights field.
func (s *SetDefaultChannelAdministratorRightsRequest) GetDefaultChannelAdministratorRights() (value ChatAdministratorRights) {
	if s == nil {
		return
	}
	return s.DefaultChannelAdministratorRights
}

// SetDefaultChannelAdministratorRights invokes method setDefaultChannelAdministratorRights#f20d5e19 returning error if any.
func (c *Client) SetDefaultChannelAdministratorRights(ctx context.Context, defaultchanneladministratorrights ChatAdministratorRights) error {
	var ok Ok

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