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

// SetChatPaidMessageStarCountRequest represents TL type `setChatPaidMessageStarCount#b93f0117`.
type SetChatPaidMessageStarCountRequest struct {
	// Identifier of the supergroup chat
	ChatID int64
	// The new number of Telegram Stars that must be paid for each message that is sent to
	// the supergroup chat unless the sender is an administrator of the chat;
	// 0-getOption("paid_message_star_count_max").
	PaidMessageStarCount int64
}

// SetChatPaidMessageStarCountRequestTypeID is TL type id of SetChatPaidMessageStarCountRequest.
const SetChatPaidMessageStarCountRequestTypeID = 0xb93f0117

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

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func (s *SetChatPaidMessageStarCountRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setChatPaidMessageStarCount#b93f0117 as nil")
	}
	b.PutID(SetChatPaidMessageStarCountRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetChatPaidMessageStarCountRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setChatPaidMessageStarCount#b93f0117 as nil")
	}
	b.PutInt53(s.ChatID)
	b.PutInt53(s.PaidMessageStarCount)
	return nil
}

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

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

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetChatPaidMessageStarCountRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setChatPaidMessageStarCount#b93f0117 as nil")
	}
	b.ObjStart()
	b.PutID("setChatPaidMessageStarCount")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(s.ChatID)
	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 *SetChatPaidMessageStarCountRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode setChatPaidMessageStarCount#b93f0117 to nil")
	}

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

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

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

// SetChatPaidMessageStarCount invokes method setChatPaidMessageStarCount#b93f0117 returning error if any.
func (c *Client) SetChatPaidMessageStarCount(ctx context.Context, request *SetChatPaidMessageStarCountRequest) error {
	var ok Ok

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