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

// CanPostStoryResultOk represents TL type `canPostStoryResultOk#7c2b31ea`.
type CanPostStoryResultOk struct {
	// Number of stories that can be posted by the user
	StoryCount int32
}

// CanPostStoryResultOkTypeID is TL type id of CanPostStoryResultOk.
const CanPostStoryResultOkTypeID = 0x7c2b31ea

// construct implements constructor of CanPostStoryResultClass.
func (c CanPostStoryResultOk) construct() CanPostStoryResultClass { return &c }

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

	_ CanPostStoryResultClass = &CanPostStoryResultOk{}
)

func (c *CanPostStoryResultOk) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.StoryCount == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *CanPostStoryResultOk) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "canPostStoryResultOk",
		ID:   CanPostStoryResultOkTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "StoryCount",
			SchemaName: "story_count",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *CanPostStoryResultOk) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultOk#7c2b31ea as nil")
	}
	b.PutID(CanPostStoryResultOkTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CanPostStoryResultOk) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultOk#7c2b31ea as nil")
	}
	b.PutInt32(c.StoryCount)
	return nil
}

// Decode implements bin.Decoder.
func (c *CanPostStoryResultOk) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canPostStoryResultOk#7c2b31ea to nil")
	}
	if err := b.ConsumeID(CanPostStoryResultOkTypeID); err != nil {
		return fmt.Errorf("unable to decode canPostStoryResultOk#7c2b31ea: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CanPostStoryResultOk) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canPostStoryResultOk#7c2b31ea to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode canPostStoryResultOk#7c2b31ea: field story_count: %w", err)
		}
		c.StoryCount = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CanPostStoryResultOk) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultOk#7c2b31ea as nil")
	}
	b.ObjStart()
	b.PutID("canPostStoryResultOk")
	b.Comma()
	b.FieldStart("story_count")
	b.PutInt32(c.StoryCount)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CanPostStoryResultOk) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode canPostStoryResultOk#7c2b31ea to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("canPostStoryResultOk"); err != nil {
				return fmt.Errorf("unable to decode canPostStoryResultOk#7c2b31ea: %w", err)
			}
		case "story_count":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode canPostStoryResultOk#7c2b31ea: field story_count: %w", err)
			}
			c.StoryCount = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetStoryCount returns value of StoryCount field.
func (c *CanPostStoryResultOk) GetStoryCount() (value int32) {
	if c == nil {
		return
	}
	return c.StoryCount
}

// CanPostStoryResultPremiumNeeded represents TL type `canPostStoryResultPremiumNeeded#37bcf585`.
type CanPostStoryResultPremiumNeeded struct {
}

// CanPostStoryResultPremiumNeededTypeID is TL type id of CanPostStoryResultPremiumNeeded.
const CanPostStoryResultPremiumNeededTypeID = 0x37bcf585

// construct implements constructor of CanPostStoryResultClass.
func (c CanPostStoryResultPremiumNeeded) construct() CanPostStoryResultClass { return &c }

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

	_ CanPostStoryResultClass = &CanPostStoryResultPremiumNeeded{}
)

func (c *CanPostStoryResultPremiumNeeded) Zero() bool {
	if c == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *CanPostStoryResultPremiumNeeded) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "canPostStoryResultPremiumNeeded",
		ID:   CanPostStoryResultPremiumNeededTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (c *CanPostStoryResultPremiumNeeded) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultPremiumNeeded#37bcf585 as nil")
	}
	b.PutID(CanPostStoryResultPremiumNeededTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CanPostStoryResultPremiumNeeded) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultPremiumNeeded#37bcf585 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *CanPostStoryResultPremiumNeeded) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canPostStoryResultPremiumNeeded#37bcf585 to nil")
	}
	if err := b.ConsumeID(CanPostStoryResultPremiumNeededTypeID); err != nil {
		return fmt.Errorf("unable to decode canPostStoryResultPremiumNeeded#37bcf585: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CanPostStoryResultPremiumNeeded) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canPostStoryResultPremiumNeeded#37bcf585 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CanPostStoryResultPremiumNeeded) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultPremiumNeeded#37bcf585 as nil")
	}
	b.ObjStart()
	b.PutID("canPostStoryResultPremiumNeeded")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CanPostStoryResultPremiumNeeded) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode canPostStoryResultPremiumNeeded#37bcf585 to nil")
	}

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

// CanPostStoryResultBoostNeeded represents TL type `canPostStoryResultBoostNeeded#4c875b3`.
type CanPostStoryResultBoostNeeded struct {
}

// CanPostStoryResultBoostNeededTypeID is TL type id of CanPostStoryResultBoostNeeded.
const CanPostStoryResultBoostNeededTypeID = 0x4c875b3

// construct implements constructor of CanPostStoryResultClass.
func (c CanPostStoryResultBoostNeeded) construct() CanPostStoryResultClass { return &c }

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

	_ CanPostStoryResultClass = &CanPostStoryResultBoostNeeded{}
)

func (c *CanPostStoryResultBoostNeeded) Zero() bool {
	if c == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *CanPostStoryResultBoostNeeded) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "canPostStoryResultBoostNeeded",
		ID:   CanPostStoryResultBoostNeededTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (c *CanPostStoryResultBoostNeeded) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultBoostNeeded#4c875b3 as nil")
	}
	b.PutID(CanPostStoryResultBoostNeededTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CanPostStoryResultBoostNeeded) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultBoostNeeded#4c875b3 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *CanPostStoryResultBoostNeeded) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canPostStoryResultBoostNeeded#4c875b3 to nil")
	}
	if err := b.ConsumeID(CanPostStoryResultBoostNeededTypeID); err != nil {
		return fmt.Errorf("unable to decode canPostStoryResultBoostNeeded#4c875b3: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CanPostStoryResultBoostNeeded) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canPostStoryResultBoostNeeded#4c875b3 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CanPostStoryResultBoostNeeded) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultBoostNeeded#4c875b3 as nil")
	}
	b.ObjStart()
	b.PutID("canPostStoryResultBoostNeeded")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CanPostStoryResultBoostNeeded) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode canPostStoryResultBoostNeeded#4c875b3 to nil")
	}

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

// CanPostStoryResultActiveStoryLimitExceeded represents TL type `canPostStoryResultActiveStoryLimitExceeded#9e340126`.
type CanPostStoryResultActiveStoryLimitExceeded struct {
}

// CanPostStoryResultActiveStoryLimitExceededTypeID is TL type id of CanPostStoryResultActiveStoryLimitExceeded.
const CanPostStoryResultActiveStoryLimitExceededTypeID = 0x9e340126

// construct implements constructor of CanPostStoryResultClass.
func (c CanPostStoryResultActiveStoryLimitExceeded) construct() CanPostStoryResultClass { return &c }

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

	_ CanPostStoryResultClass = &CanPostStoryResultActiveStoryLimitExceeded{}
)

func (c *CanPostStoryResultActiveStoryLimitExceeded) Zero() bool {
	if c == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *CanPostStoryResultActiveStoryLimitExceeded) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "canPostStoryResultActiveStoryLimitExceeded",
		ID:   CanPostStoryResultActiveStoryLimitExceededTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (c *CanPostStoryResultActiveStoryLimitExceeded) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultActiveStoryLimitExceeded#9e340126 as nil")
	}
	b.PutID(CanPostStoryResultActiveStoryLimitExceededTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CanPostStoryResultActiveStoryLimitExceeded) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultActiveStoryLimitExceeded#9e340126 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *CanPostStoryResultActiveStoryLimitExceeded) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canPostStoryResultActiveStoryLimitExceeded#9e340126 to nil")
	}
	if err := b.ConsumeID(CanPostStoryResultActiveStoryLimitExceededTypeID); err != nil {
		return fmt.Errorf("unable to decode canPostStoryResultActiveStoryLimitExceeded#9e340126: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CanPostStoryResultActiveStoryLimitExceeded) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canPostStoryResultActiveStoryLimitExceeded#9e340126 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CanPostStoryResultActiveStoryLimitExceeded) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultActiveStoryLimitExceeded#9e340126 as nil")
	}
	b.ObjStart()
	b.PutID("canPostStoryResultActiveStoryLimitExceeded")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CanPostStoryResultActiveStoryLimitExceeded) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode canPostStoryResultActiveStoryLimitExceeded#9e340126 to nil")
	}

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

// CanPostStoryResultWeeklyLimitExceeded represents TL type `canPostStoryResultWeeklyLimitExceeded#20f3f3ed`.
type CanPostStoryResultWeeklyLimitExceeded struct {
	// Time left before the user can post the next story
	RetryAfter int32
}

// CanPostStoryResultWeeklyLimitExceededTypeID is TL type id of CanPostStoryResultWeeklyLimitExceeded.
const CanPostStoryResultWeeklyLimitExceededTypeID = 0x20f3f3ed

// construct implements constructor of CanPostStoryResultClass.
func (c CanPostStoryResultWeeklyLimitExceeded) construct() CanPostStoryResultClass { return &c }

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

	_ CanPostStoryResultClass = &CanPostStoryResultWeeklyLimitExceeded{}
)

func (c *CanPostStoryResultWeeklyLimitExceeded) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.RetryAfter == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *CanPostStoryResultWeeklyLimitExceeded) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "canPostStoryResultWeeklyLimitExceeded",
		ID:   CanPostStoryResultWeeklyLimitExceededTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "RetryAfter",
			SchemaName: "retry_after",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *CanPostStoryResultWeeklyLimitExceeded) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultWeeklyLimitExceeded#20f3f3ed as nil")
	}
	b.PutID(CanPostStoryResultWeeklyLimitExceededTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CanPostStoryResultWeeklyLimitExceeded) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultWeeklyLimitExceeded#20f3f3ed as nil")
	}
	b.PutInt32(c.RetryAfter)
	return nil
}

// Decode implements bin.Decoder.
func (c *CanPostStoryResultWeeklyLimitExceeded) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canPostStoryResultWeeklyLimitExceeded#20f3f3ed to nil")
	}
	if err := b.ConsumeID(CanPostStoryResultWeeklyLimitExceededTypeID); err != nil {
		return fmt.Errorf("unable to decode canPostStoryResultWeeklyLimitExceeded#20f3f3ed: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *CanPostStoryResultWeeklyLimitExceeded) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canPostStoryResultWeeklyLimitExceeded#20f3f3ed to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode canPostStoryResultWeeklyLimitExceeded#20f3f3ed: field retry_after: %w", err)
		}
		c.RetryAfter = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CanPostStoryResultWeeklyLimitExceeded) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultWeeklyLimitExceeded#20f3f3ed as nil")
	}
	b.ObjStart()
	b.PutID("canPostStoryResultWeeklyLimitExceeded")
	b.Comma()
	b.FieldStart("retry_after")
	b.PutInt32(c.RetryAfter)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *CanPostStoryResultWeeklyLimitExceeded) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode canPostStoryResultWeeklyLimitExceeded#20f3f3ed to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("canPostStoryResultWeeklyLimitExceeded"); err != nil {
				return fmt.Errorf("unable to decode canPostStoryResultWeeklyLimitExceeded#20f3f3ed: %w", err)
			}
		case "retry_after":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode canPostStoryResultWeeklyLimitExceeded#20f3f3ed: field retry_after: %w", err)
			}
			c.RetryAfter = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetRetryAfter returns value of RetryAfter field.
func (c *CanPostStoryResultWeeklyLimitExceeded) GetRetryAfter() (value int32) {
	if c == nil {
		return
	}
	return c.RetryAfter
}

// CanPostStoryResultMonthlyLimitExceeded represents TL type `canPostStoryResultMonthlyLimitExceeded#d141ed4e`.
type CanPostStoryResultMonthlyLimitExceeded struct {
	// Time left before the user can post the next story
	RetryAfter int32
}

// CanPostStoryResultMonthlyLimitExceededTypeID is TL type id of CanPostStoryResultMonthlyLimitExceeded.
const CanPostStoryResultMonthlyLimitExceededTypeID = 0xd141ed4e

// construct implements constructor of CanPostStoryResultClass.
func (c CanPostStoryResultMonthlyLimitExceeded) construct() CanPostStoryResultClass { return &c }

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

	_ CanPostStoryResultClass = &CanPostStoryResultMonthlyLimitExceeded{}
)

func (c *CanPostStoryResultMonthlyLimitExceeded) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.RetryAfter == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (c *CanPostStoryResultMonthlyLimitExceeded) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "canPostStoryResultMonthlyLimitExceeded",
		ID:   CanPostStoryResultMonthlyLimitExceededTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "RetryAfter",
			SchemaName: "retry_after",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *CanPostStoryResultMonthlyLimitExceeded) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultMonthlyLimitExceeded#d141ed4e as nil")
	}
	b.PutID(CanPostStoryResultMonthlyLimitExceededTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *CanPostStoryResultMonthlyLimitExceeded) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultMonthlyLimitExceeded#d141ed4e as nil")
	}
	b.PutInt32(c.RetryAfter)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (c *CanPostStoryResultMonthlyLimitExceeded) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode canPostStoryResultMonthlyLimitExceeded#d141ed4e to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode canPostStoryResultMonthlyLimitExceeded#d141ed4e: field retry_after: %w", err)
		}
		c.RetryAfter = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *CanPostStoryResultMonthlyLimitExceeded) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode canPostStoryResultMonthlyLimitExceeded#d141ed4e as nil")
	}
	b.ObjStart()
	b.PutID("canPostStoryResultMonthlyLimitExceeded")
	b.Comma()
	b.FieldStart("retry_after")
	b.PutInt32(c.RetryAfter)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("canPostStoryResultMonthlyLimitExceeded"); err != nil {
				return fmt.Errorf("unable to decode canPostStoryResultMonthlyLimitExceeded#d141ed4e: %w", err)
			}
		case "retry_after":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode canPostStoryResultMonthlyLimitExceeded#d141ed4e: field retry_after: %w", err)
			}
			c.RetryAfter = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetRetryAfter returns value of RetryAfter field.
func (c *CanPostStoryResultMonthlyLimitExceeded) GetRetryAfter() (value int32) {
	if c == nil {
		return
	}
	return c.RetryAfter
}

// CanPostStoryResultClassName is schema name of CanPostStoryResultClass.
const CanPostStoryResultClassName = "CanPostStoryResult"

// CanPostStoryResultClass represents CanPostStoryResult generic type.
//
// Example:
//
//	g, err := tdapi.DecodeCanPostStoryResult(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.CanPostStoryResultOk: // canPostStoryResultOk#7c2b31ea
//	case *tdapi.CanPostStoryResultPremiumNeeded: // canPostStoryResultPremiumNeeded#37bcf585
//	case *tdapi.CanPostStoryResultBoostNeeded: // canPostStoryResultBoostNeeded#4c875b3
//	case *tdapi.CanPostStoryResultActiveStoryLimitExceeded: // canPostStoryResultActiveStoryLimitExceeded#9e340126
//	case *tdapi.CanPostStoryResultWeeklyLimitExceeded: // canPostStoryResultWeeklyLimitExceeded#20f3f3ed
//	case *tdapi.CanPostStoryResultMonthlyLimitExceeded: // canPostStoryResultMonthlyLimitExceeded#d141ed4e
//	default: panic(v)
//	}
type CanPostStoryResultClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() CanPostStoryResultClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	EncodeTDLibJSON(b tdjson.Encoder) error
	DecodeTDLibJSON(b tdjson.Decoder) error
}

// DecodeCanPostStoryResult implements binary de-serialization for CanPostStoryResultClass.
func DecodeCanPostStoryResult(buf *bin.Buffer) (CanPostStoryResultClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case CanPostStoryResultOkTypeID:
		// Decoding canPostStoryResultOk#7c2b31ea.
		v := CanPostStoryResultOk{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanPostStoryResultClass: %w", err)
		}
		return &v, nil
	case CanPostStoryResultPremiumNeededTypeID:
		// Decoding canPostStoryResultPremiumNeeded#37bcf585.
		v := CanPostStoryResultPremiumNeeded{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanPostStoryResultClass: %w", err)
		}
		return &v, nil
	case CanPostStoryResultBoostNeededTypeID:
		// Decoding canPostStoryResultBoostNeeded#4c875b3.
		v := CanPostStoryResultBoostNeeded{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanPostStoryResultClass: %w", err)
		}
		return &v, nil
	case CanPostStoryResultActiveStoryLimitExceededTypeID:
		// Decoding canPostStoryResultActiveStoryLimitExceeded#9e340126.
		v := CanPostStoryResultActiveStoryLimitExceeded{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanPostStoryResultClass: %w", err)
		}
		return &v, nil
	case CanPostStoryResultWeeklyLimitExceededTypeID:
		// Decoding canPostStoryResultWeeklyLimitExceeded#20f3f3ed.
		v := CanPostStoryResultWeeklyLimitExceeded{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanPostStoryResultClass: %w", err)
		}
		return &v, nil
	case CanPostStoryResultMonthlyLimitExceededTypeID:
		// Decoding canPostStoryResultMonthlyLimitExceeded#d141ed4e.
		v := CanPostStoryResultMonthlyLimitExceeded{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanPostStoryResultClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode CanPostStoryResultClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONCanPostStoryResult implements binary de-serialization for CanPostStoryResultClass.
func DecodeTDLibJSONCanPostStoryResult(buf tdjson.Decoder) (CanPostStoryResultClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "canPostStoryResultOk":
		// Decoding canPostStoryResultOk#7c2b31ea.
		v := CanPostStoryResultOk{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanPostStoryResultClass: %w", err)
		}
		return &v, nil
	case "canPostStoryResultPremiumNeeded":
		// Decoding canPostStoryResultPremiumNeeded#37bcf585.
		v := CanPostStoryResultPremiumNeeded{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanPostStoryResultClass: %w", err)
		}
		return &v, nil
	case "canPostStoryResultBoostNeeded":
		// Decoding canPostStoryResultBoostNeeded#4c875b3.
		v := CanPostStoryResultBoostNeeded{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanPostStoryResultClass: %w", err)
		}
		return &v, nil
	case "canPostStoryResultActiveStoryLimitExceeded":
		// Decoding canPostStoryResultActiveStoryLimitExceeded#9e340126.
		v := CanPostStoryResultActiveStoryLimitExceeded{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanPostStoryResultClass: %w", err)
		}
		return &v, nil
	case "canPostStoryResultWeeklyLimitExceeded":
		// Decoding canPostStoryResultWeeklyLimitExceeded#20f3f3ed.
		v := CanPostStoryResultWeeklyLimitExceeded{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanPostStoryResultClass: %w", err)
		}
		return &v, nil
	case "canPostStoryResultMonthlyLimitExceeded":
		// Decoding canPostStoryResultMonthlyLimitExceeded#d141ed4e.
		v := CanPostStoryResultMonthlyLimitExceeded{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode CanPostStoryResultClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode CanPostStoryResultClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// CanPostStoryResult boxes the CanPostStoryResultClass providing a helper.
type CanPostStoryResultBox struct {
	CanPostStoryResult CanPostStoryResultClass
}

// Decode implements bin.Decoder for CanPostStoryResultBox.
func (b *CanPostStoryResultBox) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("unable to decode CanPostStoryResultBox to nil")
	}
	v, err := DecodeCanPostStoryResult(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.CanPostStoryResult = v
	return nil
}

// Encode implements bin.Encode for CanPostStoryResultBox.
func (b *CanPostStoryResultBox) Encode(buf *bin.Buffer) error {
	if b == nil || b.CanPostStoryResult == nil {
		return fmt.Errorf("unable to encode CanPostStoryResultClass as nil")
	}
	return b.CanPostStoryResult.Encode(buf)
}

// DecodeTDLibJSON implements bin.Decoder for CanPostStoryResultBox.
func (b *CanPostStoryResultBox) DecodeTDLibJSON(buf tdjson.Decoder) error {
	if b == nil {
		return fmt.Errorf("unable to decode CanPostStoryResultBox to nil")
	}
	v, err := DecodeTDLibJSONCanPostStoryResult(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.CanPostStoryResult = v
	return nil
}

// EncodeTDLibJSON implements bin.Encode for CanPostStoryResultBox.
func (b *CanPostStoryResultBox) EncodeTDLibJSON(buf tdjson.Encoder) error {
	if b == nil || b.CanPostStoryResult == nil {
		return fmt.Errorf("unable to encode CanPostStoryResultClass as nil")
	}
	return b.CanPostStoryResult.EncodeTDLibJSON(buf)
}
