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

// SetChatDirectMessagesGroupRequest represents TL type `setChatDirectMessagesGroup#6157e4a3`.
type SetChatDirectMessagesGroupRequest struct {
	// Identifier of the channel chat
	ChatID int64
	// Pass true if the direct messages group is enabled for the channel chat; pass false
	// otherwise
	IsEnabled bool
	// The new number of Telegram Stars that must be paid for each message that is sent to
	// the direct messages chat unless the sender is an administrator of the channel chat;
	// 0-getOption("paid_message_star_count_max").
	PaidMessageStarCount int64
}

// SetChatDirectMessagesGroupRequestTypeID is TL type id of SetChatDirectMessagesGroupRequest.
const SetChatDirectMessagesGroupRequestTypeID = 0x6157e4a3

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

func (s *SetChatDirectMessagesGroupRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.ChatID == 0) {
		return false
	}
	if !(s.IsEnabled == false) {
		return false
	}
	if !(s.PaidMessageStarCount == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetChatDirectMessagesGroupRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setChatDirectMessagesGroup",
		ID:   SetChatDirectMessagesGroupRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "IsEnabled",
			SchemaName: "is_enabled",
		},
		{
			Name:       "PaidMessageStarCount",
			SchemaName: "paid_message_star_count",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetChatDirectMessagesGroupRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setChatDirectMessagesGroup#6157e4a3 as nil")
	}
	b.PutID(SetChatDirectMessagesGroupRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetChatDirectMessagesGroupRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setChatDirectMessagesGroup#6157e4a3 as nil")
	}
	b.PutInt53(s.ChatID)
	b.PutBool(s.IsEnabled)
	b.PutInt53(s.PaidMessageStarCount)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *SetChatDirectMessagesGroupRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setChatDirectMessagesGroup#6157e4a3 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode setChatDirectMessagesGroup#6157e4a3: field chat_id: %w", err)
		}
		s.ChatID = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode setChatDirectMessagesGroup#6157e4a3: field is_enabled: %w", err)
		}
		s.IsEnabled = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode setChatDirectMessagesGroup#6157e4a3: field paid_message_star_count: %w", err)
		}
		s.PaidMessageStarCount = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetChatDirectMessagesGroupRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setChatDirectMessagesGroup#6157e4a3 as nil")
	}
	b.ObjStart()
	b.PutID("setChatDirectMessagesGroup")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(s.ChatID)
	b.Comma()
	b.FieldStart("is_enabled")
	b.PutBool(s.IsEnabled)
	b.Comma()
	b.FieldStart("paid_message_star_count")
	b.PutInt53(s.PaidMessageStarCount)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setChatDirectMessagesGroup"); err != nil {
				return fmt.Errorf("unable to decode setChatDirectMessagesGroup#6157e4a3: %w", err)
			}
		case "chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode setChatDirectMessagesGroup#6157e4a3: field chat_id: %w", err)
			}
			s.ChatID = value
		case "is_enabled":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode setChatDirectMessagesGroup#6157e4a3: field is_enabled: %w", err)
			}
			s.IsEnabled = value
		case "paid_message_star_count":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode setChatDirectMessagesGroup#6157e4a3: field paid_message_star_count: %w", err)
			}
			s.PaidMessageStarCount = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetChatID returns value of ChatID field.
func (s *SetChatDirectMessagesGroupRequest) GetChatID() (value int64) {
	if s == nil {
		return
	}
	return s.ChatID
}

// GetIsEnabled returns value of IsEnabled field.
func (s *SetChatDirectMessagesGroupRequest) GetIsEnabled() (value bool) {
	if s == nil {
		return
	}
	return s.IsEnabled
}

// GetPaidMessageStarCount returns value of PaidMessageStarCount field.
func (s *SetChatDirectMessagesGroupRequest) GetPaidMessageStarCount() (value int64) {
	if s == nil {
		return
	}
	return s.PaidMessageStarCount
}

// SetChatDirectMessagesGroup invokes method setChatDirectMessagesGroup#6157e4a3 returning error if any.
func (c *Client) SetChatDirectMessagesGroup(ctx context.Context, request *SetChatDirectMessagesGroupRequest) error {
	var ok Ok

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