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

// DeleteBusinessStoryRequest represents TL type `deleteBusinessStory#3d11ed52`.
type DeleteBusinessStoryRequest struct {
	// Unique identifier of business connection
	BusinessConnectionID string
	// Identifier of the story to delete
	StoryID int32
}

// DeleteBusinessStoryRequestTypeID is TL type id of DeleteBusinessStoryRequest.
const DeleteBusinessStoryRequestTypeID = 0x3d11ed52

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

func (d *DeleteBusinessStoryRequest) Zero() bool {
	if d == nil {
		return true
	}
	if !(d.BusinessConnectionID == "") {
		return false
	}
	if !(d.StoryID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (d *DeleteBusinessStoryRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "deleteBusinessStory",
		ID:   DeleteBusinessStoryRequestTypeID,
	}
	if d == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BusinessConnectionID",
			SchemaName: "business_connection_id",
		},
		{
			Name:       "StoryID",
			SchemaName: "story_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (d *DeleteBusinessStoryRequest) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteBusinessStory#3d11ed52 as nil")
	}
	b.PutID(DeleteBusinessStoryRequestTypeID)
	return d.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (d *DeleteBusinessStoryRequest) EncodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteBusinessStory#3d11ed52 as nil")
	}
	b.PutString(d.BusinessConnectionID)
	b.PutInt32(d.StoryID)
	return nil
}

// Decode implements bin.Decoder.
func (d *DeleteBusinessStoryRequest) Decode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode deleteBusinessStory#3d11ed52 to nil")
	}
	if err := b.ConsumeID(DeleteBusinessStoryRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode deleteBusinessStory#3d11ed52: %w", err)
	}
	return d.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (d *DeleteBusinessStoryRequest) DecodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode deleteBusinessStory#3d11ed52 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode deleteBusinessStory#3d11ed52: field business_connection_id: %w", err)
		}
		d.BusinessConnectionID = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode deleteBusinessStory#3d11ed52: field story_id: %w", err)
		}
		d.StoryID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (d *DeleteBusinessStoryRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if d == nil {
		return fmt.Errorf("can't encode deleteBusinessStory#3d11ed52 as nil")
	}
	b.ObjStart()
	b.PutID("deleteBusinessStory")
	b.Comma()
	b.FieldStart("business_connection_id")
	b.PutString(d.BusinessConnectionID)
	b.Comma()
	b.FieldStart("story_id")
	b.PutInt32(d.StoryID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (d *DeleteBusinessStoryRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if d == nil {
		return fmt.Errorf("can't decode deleteBusinessStory#3d11ed52 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("deleteBusinessStory"); err != nil {
				return fmt.Errorf("unable to decode deleteBusinessStory#3d11ed52: %w", err)
			}
		case "business_connection_id":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode deleteBusinessStory#3d11ed52: field business_connection_id: %w", err)
			}
			d.BusinessConnectionID = value
		case "story_id":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode deleteBusinessStory#3d11ed52: field story_id: %w", err)
			}
			d.StoryID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetBusinessConnectionID returns value of BusinessConnectionID field.
func (d *DeleteBusinessStoryRequest) GetBusinessConnectionID() (value string) {
	if d == nil {
		return
	}
	return d.BusinessConnectionID
}

// GetStoryID returns value of StoryID field.
func (d *DeleteBusinessStoryRequest) GetStoryID() (value int32) {
	if d == nil {
		return
	}
	return d.StoryID
}

// DeleteBusinessStory invokes method deleteBusinessStory#3d11ed52 returning error if any.
func (c *Client) DeleteBusinessStory(ctx context.Context, request *DeleteBusinessStoryRequest) error {
	var ok Ok

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