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

// AicomposeCreateToneRequest represents TL type `aicompose.createTone#4aa83913`.
//
// See https://core.telegram.org/method/aicompose.createTone for reference.
type AicomposeCreateToneRequest struct {
	// Flags field of AicomposeCreateToneRequest.
	Flags bin.Fields
	// DisplayAuthor field of AicomposeCreateToneRequest.
	DisplayAuthor bool
	// EmojiID field of AicomposeCreateToneRequest.
	EmojiID int64
	// Title field of AicomposeCreateToneRequest.
	Title string
	// Prompt field of AicomposeCreateToneRequest.
	Prompt string
}

// AicomposeCreateToneRequestTypeID is TL type id of AicomposeCreateToneRequest.
const AicomposeCreateToneRequestTypeID = 0x4aa83913

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

func (c *AicomposeCreateToneRequest) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.Flags.Zero()) {
		return false
	}
	if !(c.DisplayAuthor == false) {
		return false
	}
	if !(c.EmojiID == 0) {
		return false
	}
	if !(c.Title == "") {
		return false
	}
	if !(c.Prompt == "") {
		return false
	}

	return true
}

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

// FillFrom fills AicomposeCreateToneRequest from given interface.
func (c *AicomposeCreateToneRequest) FillFrom(from interface {
	GetDisplayAuthor() (value bool)
	GetEmojiID() (value int64)
	GetTitle() (value string)
	GetPrompt() (value string)
}) {
	c.DisplayAuthor = from.GetDisplayAuthor()
	c.EmojiID = from.GetEmojiID()
	c.Title = from.GetTitle()
	c.Prompt = from.GetPrompt()
}

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

// TypeName returns name of type in TL schema.
func (*AicomposeCreateToneRequest) TypeName() string {
	return "aicompose.createTone"
}

// TypeInfo returns info about TL type.
func (c *AicomposeCreateToneRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "aicompose.createTone",
		ID:   AicomposeCreateToneRequestTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "DisplayAuthor",
			SchemaName: "display_author",
			Null:       !c.Flags.Has(0),
		},
		{
			Name:       "EmojiID",
			SchemaName: "emoji_id",
		},
		{
			Name:       "Title",
			SchemaName: "title",
		},
		{
			Name:       "Prompt",
			SchemaName: "prompt",
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (c *AicomposeCreateToneRequest) SetFlags() {
	if !(c.DisplayAuthor == false) {
		c.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func (c *AicomposeCreateToneRequest) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode aicompose.createTone#4aa83913 as nil")
	}
	b.PutID(AicomposeCreateToneRequestTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *AicomposeCreateToneRequest) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode aicompose.createTone#4aa83913 as nil")
	}
	c.SetFlags()
	if err := c.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode aicompose.createTone#4aa83913: field flags: %w", err)
	}
	b.PutLong(c.EmojiID)
	b.PutString(c.Title)
	b.PutString(c.Prompt)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (c *AicomposeCreateToneRequest) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode aicompose.createTone#4aa83913 to nil")
	}
	{
		if err := c.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode aicompose.createTone#4aa83913: field flags: %w", err)
		}
	}
	c.DisplayAuthor = c.Flags.Has(0)
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode aicompose.createTone#4aa83913: field emoji_id: %w", err)
		}
		c.EmojiID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode aicompose.createTone#4aa83913: field title: %w", err)
		}
		c.Title = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode aicompose.createTone#4aa83913: field prompt: %w", err)
		}
		c.Prompt = value
	}
	return nil
}

// SetDisplayAuthor sets value of DisplayAuthor conditional field.
func (c *AicomposeCreateToneRequest) SetDisplayAuthor(value bool) {
	if value {
		c.Flags.Set(0)
		c.DisplayAuthor = true
	} else {
		c.Flags.Unset(0)
		c.DisplayAuthor = false
	}
}

// GetDisplayAuthor returns value of DisplayAuthor conditional field.
func (c *AicomposeCreateToneRequest) GetDisplayAuthor() (value bool) {
	if c == nil {
		return
	}
	return c.Flags.Has(0)
}

// GetEmojiID returns value of EmojiID field.
func (c *AicomposeCreateToneRequest) GetEmojiID() (value int64) {
	if c == nil {
		return
	}
	return c.EmojiID
}

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

// GetPrompt returns value of Prompt field.
func (c *AicomposeCreateToneRequest) GetPrompt() (value string) {
	if c == nil {
		return
	}
	return c.Prompt
}

// AicomposeCreateTone invokes method aicompose.createTone#4aa83913 returning error if any.
//
// See https://core.telegram.org/method/aicompose.createTone for reference.
func (c *Client) AicomposeCreateTone(ctx context.Context, request *AicomposeCreateToneRequest) (AiComposeToneClass, error) {
	var result AiComposeToneBox

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