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

// StoriesTogglePeerStoriesHiddenRequest represents TL type `stories.togglePeerStoriesHidden#bd0415c4`.
// Hide the active stories of a user, preventing them from being displayed on the action
// bar on the homescreen, see here »¹ for more info.
//
// Links:
//  1. https://core.telegram.org/api/stories#hiding-stories-of-other-users
//
// See https://core.telegram.org/method/stories.togglePeerStoriesHidden for reference.
type StoriesTogglePeerStoriesHiddenRequest struct {
	// Peer whose stories should be (un)hidden.
	Peer InputPeerClass
	// Whether to hide or unhide stories.
	Hidden bool
}

// StoriesTogglePeerStoriesHiddenRequestTypeID is TL type id of StoriesTogglePeerStoriesHiddenRequest.
const StoriesTogglePeerStoriesHiddenRequestTypeID = 0xbd0415c4

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

func (t *StoriesTogglePeerStoriesHiddenRequest) Zero() bool {
	if t == nil {
		return true
	}
	if !(t.Peer == nil) {
		return false
	}
	if !(t.Hidden == false) {
		return false
	}

	return true
}

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

// FillFrom fills StoriesTogglePeerStoriesHiddenRequest from given interface.
func (t *StoriesTogglePeerStoriesHiddenRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetHidden() (value bool)
}) {
	t.Peer = from.GetPeer()
	t.Hidden = from.GetHidden()
}

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

// TypeName returns name of type in TL schema.
func (*StoriesTogglePeerStoriesHiddenRequest) TypeName() string {
	return "stories.togglePeerStoriesHidden"
}

// TypeInfo returns info about TL type.
func (t *StoriesTogglePeerStoriesHiddenRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "stories.togglePeerStoriesHidden",
		ID:   StoriesTogglePeerStoriesHiddenRequestTypeID,
	}
	if t == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "Hidden",
			SchemaName: "hidden",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (t *StoriesTogglePeerStoriesHiddenRequest) Encode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode stories.togglePeerStoriesHidden#bd0415c4 as nil")
	}
	b.PutID(StoriesTogglePeerStoriesHiddenRequestTypeID)
	return t.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (t *StoriesTogglePeerStoriesHiddenRequest) EncodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't encode stories.togglePeerStoriesHidden#bd0415c4 as nil")
	}
	if t.Peer == nil {
		return fmt.Errorf("unable to encode stories.togglePeerStoriesHidden#bd0415c4: field peer is nil")
	}
	if err := t.Peer.Encode(b); err != nil {
		return fmt.Errorf("unable to encode stories.togglePeerStoriesHidden#bd0415c4: field peer: %w", err)
	}
	b.PutBool(t.Hidden)
	return nil
}

// Decode implements bin.Decoder.
func (t *StoriesTogglePeerStoriesHiddenRequest) Decode(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode stories.togglePeerStoriesHidden#bd0415c4 to nil")
	}
	if err := b.ConsumeID(StoriesTogglePeerStoriesHiddenRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode stories.togglePeerStoriesHidden#bd0415c4: %w", err)
	}
	return t.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (t *StoriesTogglePeerStoriesHiddenRequest) DecodeBare(b *bin.Buffer) error {
	if t == nil {
		return fmt.Errorf("can't decode stories.togglePeerStoriesHidden#bd0415c4 to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode stories.togglePeerStoriesHidden#bd0415c4: field peer: %w", err)
		}
		t.Peer = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode stories.togglePeerStoriesHidden#bd0415c4: field hidden: %w", err)
		}
		t.Hidden = value
	}
	return nil
}

// GetPeer returns value of Peer field.
func (t *StoriesTogglePeerStoriesHiddenRequest) GetPeer() (value InputPeerClass) {
	if t == nil {
		return
	}
	return t.Peer
}

// GetHidden returns value of Hidden field.
func (t *StoriesTogglePeerStoriesHiddenRequest) GetHidden() (value bool) {
	if t == nil {
		return
	}
	return t.Hidden
}

// StoriesTogglePeerStoriesHidden invokes method stories.togglePeerStoriesHidden#bd0415c4 returning error if any.
// Hide the active stories of a user, preventing them from being displayed on the action
// bar on the homescreen, see here »¹ for more info.
//
// Links:
//  1. https://core.telegram.org/api/stories#hiding-stories-of-other-users
//
// Possible errors:
//
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//
// See https://core.telegram.org/method/stories.togglePeerStoriesHidden for reference.
func (c *Client) StoriesTogglePeerStoriesHidden(ctx context.Context, request *StoriesTogglePeerStoriesHiddenRequest) (bool, error) {
	var result BoolBox

	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return false, err
	}
	_, ok := result.Bool.(*BoolTrue)
	return ok, nil
}
