// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// MessagesEditChatCreatorRequest represents TL type `messages.editChatCreator#f743b857`.
//
// See https://core.telegram.org/method/messages.editChatCreator for reference.
type MessagesEditChatCreatorRequest struct {
	// Peer field of MessagesEditChatCreatorRequest.
	Peer InputPeerClass
	// UserID field of MessagesEditChatCreatorRequest.
	UserID InputUserClass
	// Password field of MessagesEditChatCreatorRequest.
	Password InputCheckPasswordSRPClass
}

// MessagesEditChatCreatorRequestTypeID is TL type id of MessagesEditChatCreatorRequest.
const MessagesEditChatCreatorRequestTypeID = 0xf743b857

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

func (e *MessagesEditChatCreatorRequest) Zero() bool {
	if e == nil {
		return true
	}
	if !(e.Peer == nil) {
		return false
	}
	if !(e.UserID == nil) {
		return false
	}
	if !(e.Password == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesEditChatCreatorRequest from given interface.
func (e *MessagesEditChatCreatorRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetUserID() (value InputUserClass)
	GetPassword() (value InputCheckPasswordSRPClass)
}) {
	e.Peer = from.GetPeer()
	e.UserID = from.GetUserID()
	e.Password = from.GetPassword()
}

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

// TypeName returns name of type in TL schema.
func (*MessagesEditChatCreatorRequest) TypeName() string {
	return "messages.editChatCreator"
}

// TypeInfo returns info about TL type.
func (e *MessagesEditChatCreatorRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.editChatCreator",
		ID:   MessagesEditChatCreatorRequestTypeID,
	}
	if e == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
		{
			Name:       "Password",
			SchemaName: "password",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (e *MessagesEditChatCreatorRequest) Encode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode messages.editChatCreator#f743b857 as nil")
	}
	b.PutID(MessagesEditChatCreatorRequestTypeID)
	return e.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (e *MessagesEditChatCreatorRequest) EncodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode messages.editChatCreator#f743b857 as nil")
	}
	if e.Peer == nil {
		return fmt.Errorf("unable to encode messages.editChatCreator#f743b857: field peer is nil")
	}
	if err := e.Peer.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messages.editChatCreator#f743b857: field peer: %w", err)
	}
	if e.UserID == nil {
		return fmt.Errorf("unable to encode messages.editChatCreator#f743b857: field user_id is nil")
	}
	if err := e.UserID.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messages.editChatCreator#f743b857: field user_id: %w", err)
	}
	if e.Password == nil {
		return fmt.Errorf("unable to encode messages.editChatCreator#f743b857: field password is nil")
	}
	if err := e.Password.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messages.editChatCreator#f743b857: field password: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (e *MessagesEditChatCreatorRequest) Decode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't decode messages.editChatCreator#f743b857 to nil")
	}
	if err := b.ConsumeID(MessagesEditChatCreatorRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.editChatCreator#f743b857: %w", err)
	}
	return e.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (e *MessagesEditChatCreatorRequest) DecodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't decode messages.editChatCreator#f743b857 to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode messages.editChatCreator#f743b857: field peer: %w", err)
		}
		e.Peer = value
	}
	{
		value, err := DecodeInputUser(b)
		if err != nil {
			return fmt.Errorf("unable to decode messages.editChatCreator#f743b857: field user_id: %w", err)
		}
		e.UserID = value
	}
	{
		value, err := DecodeInputCheckPasswordSRP(b)
		if err != nil {
			return fmt.Errorf("unable to decode messages.editChatCreator#f743b857: field password: %w", err)
		}
		e.Password = value
	}
	return nil
}

// GetPeer returns value of Peer field.
func (e *MessagesEditChatCreatorRequest) GetPeer() (value InputPeerClass) {
	if e == nil {
		return
	}
	return e.Peer
}

// GetUserID returns value of UserID field.
func (e *MessagesEditChatCreatorRequest) GetUserID() (value InputUserClass) {
	if e == nil {
		return
	}
	return e.UserID
}

// GetPassword returns value of Password field.
func (e *MessagesEditChatCreatorRequest) GetPassword() (value InputCheckPasswordSRPClass) {
	if e == nil {
		return
	}
	return e.Password
}

// GetPasswordAsNotEmpty returns mapped value of Password field.
func (e *MessagesEditChatCreatorRequest) GetPasswordAsNotEmpty() (*InputCheckPasswordSRP, bool) {
	return e.Password.AsNotEmpty()
}

// MessagesEditChatCreator invokes method messages.editChatCreator#f743b857 returning error if any.
//
// See https://core.telegram.org/method/messages.editChatCreator for reference.
func (c *Client) MessagesEditChatCreator(ctx context.Context, request *MessagesEditChatCreatorRequest) (UpdatesClass, error) {
	var result UpdatesBox

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