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

// InputBusinessStartPage represents TL type `inputBusinessStartPage#ec7c87e0`.
type InputBusinessStartPage struct {
	// Title text of the start page; 0-getOption("business_start_page_title_length_max")
	// characters
	Title string
	// Message text of the start page; 0-getOption("business_start_page_message_length_max")
	// characters
	Message string
	// Greeting sticker of the start page; pass null if none. The sticker must belong to a
	// sticker set and must not be a custom emoji
	Sticker InputFileClass
}

// InputBusinessStartPageTypeID is TL type id of InputBusinessStartPage.
const InputBusinessStartPageTypeID = 0xec7c87e0

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

func (i *InputBusinessStartPage) Zero() bool {
	if i == nil {
		return true
	}
	if !(i.Title == "") {
		return false
	}
	if !(i.Message == "") {
		return false
	}
	if !(i.Sticker == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (i *InputBusinessStartPage) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "inputBusinessStartPage",
		ID:   InputBusinessStartPageTypeID,
	}
	if i == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Title",
			SchemaName: "title",
		},
		{
			Name:       "Message",
			SchemaName: "message",
		},
		{
			Name:       "Sticker",
			SchemaName: "sticker",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (i *InputBusinessStartPage) Encode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputBusinessStartPage#ec7c87e0 as nil")
	}
	b.PutID(InputBusinessStartPageTypeID)
	return i.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (i *InputBusinessStartPage) EncodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't encode inputBusinessStartPage#ec7c87e0 as nil")
	}
	b.PutString(i.Title)
	b.PutString(i.Message)
	if i.Sticker == nil {
		return fmt.Errorf("unable to encode inputBusinessStartPage#ec7c87e0: field sticker is nil")
	}
	if err := i.Sticker.Encode(b); err != nil {
		return fmt.Errorf("unable to encode inputBusinessStartPage#ec7c87e0: field sticker: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (i *InputBusinessStartPage) Decode(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inputBusinessStartPage#ec7c87e0 to nil")
	}
	if err := b.ConsumeID(InputBusinessStartPageTypeID); err != nil {
		return fmt.Errorf("unable to decode inputBusinessStartPage#ec7c87e0: %w", err)
	}
	return i.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (i *InputBusinessStartPage) DecodeBare(b *bin.Buffer) error {
	if i == nil {
		return fmt.Errorf("can't decode inputBusinessStartPage#ec7c87e0 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode inputBusinessStartPage#ec7c87e0: field title: %w", err)
		}
		i.Title = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode inputBusinessStartPage#ec7c87e0: field message: %w", err)
		}
		i.Message = value
	}
	{
		value, err := DecodeInputFile(b)
		if err != nil {
			return fmt.Errorf("unable to decode inputBusinessStartPage#ec7c87e0: field sticker: %w", err)
		}
		i.Sticker = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (i *InputBusinessStartPage) EncodeTDLibJSON(b tdjson.Encoder) error {
	if i == nil {
		return fmt.Errorf("can't encode inputBusinessStartPage#ec7c87e0 as nil")
	}
	b.ObjStart()
	b.PutID("inputBusinessStartPage")
	b.Comma()
	b.FieldStart("title")
	b.PutString(i.Title)
	b.Comma()
	b.FieldStart("message")
	b.PutString(i.Message)
	b.Comma()
	b.FieldStart("sticker")
	if i.Sticker == nil {
		return fmt.Errorf("unable to encode inputBusinessStartPage#ec7c87e0: field sticker is nil")
	}
	if err := i.Sticker.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode inputBusinessStartPage#ec7c87e0: field sticker: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (i *InputBusinessStartPage) DecodeTDLibJSON(b tdjson.Decoder) error {
	if i == nil {
		return fmt.Errorf("can't decode inputBusinessStartPage#ec7c87e0 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("inputBusinessStartPage"); err != nil {
				return fmt.Errorf("unable to decode inputBusinessStartPage#ec7c87e0: %w", err)
			}
		case "title":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode inputBusinessStartPage#ec7c87e0: field title: %w", err)
			}
			i.Title = value
		case "message":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode inputBusinessStartPage#ec7c87e0: field message: %w", err)
			}
			i.Message = value
		case "sticker":
			value, err := DecodeTDLibJSONInputFile(b)
			if err != nil {
				return fmt.Errorf("unable to decode inputBusinessStartPage#ec7c87e0: field sticker: %w", err)
			}
			i.Sticker = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetTitle returns value of Title field.
func (i *InputBusinessStartPage) GetTitle() (value string) {
	if i == nil {
		return
	}
	return i.Title
}

// GetMessage returns value of Message field.
func (i *InputBusinessStartPage) GetMessage() (value string) {
	if i == nil {
		return
	}
	return i.Message
}

// GetSticker returns value of Sticker field.
func (i *InputBusinessStartPage) GetSticker() (value InputFileClass) {
	if i == nil {
		return
	}
	return i.Sticker
}
