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

// GetVideoChatInviteLinkRequest represents TL type `getVideoChatInviteLink#acde7487`.
type GetVideoChatInviteLinkRequest struct {
	// Group call identifier
	GroupCallID int32
	// Pass true if the invite link needs to contain an invite hash, passing which to
	// joinVideoChat would allow the invited user to unmute themselves. Requires groupCall
	// can_be_managed right
	CanSelfUnmute bool
}

// GetVideoChatInviteLinkRequestTypeID is TL type id of GetVideoChatInviteLinkRequest.
const GetVideoChatInviteLinkRequestTypeID = 0xacde7487

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

func (g *GetVideoChatInviteLinkRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.GroupCallID == 0) {
		return false
	}
	if !(g.CanSelfUnmute == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GetVideoChatInviteLinkRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getVideoChatInviteLink",
		ID:   GetVideoChatInviteLinkRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "GroupCallID",
			SchemaName: "group_call_id",
		},
		{
			Name:       "CanSelfUnmute",
			SchemaName: "can_self_unmute",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetVideoChatInviteLinkRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getVideoChatInviteLink#acde7487 as nil")
	}
	b.PutID(GetVideoChatInviteLinkRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetVideoChatInviteLinkRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getVideoChatInviteLink#acde7487 as nil")
	}
	b.PutInt32(g.GroupCallID)
	b.PutBool(g.CanSelfUnmute)
	return nil
}

// Decode implements bin.Decoder.
func (g *GetVideoChatInviteLinkRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getVideoChatInviteLink#acde7487 to nil")
	}
	if err := b.ConsumeID(GetVideoChatInviteLinkRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode getVideoChatInviteLink#acde7487: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *GetVideoChatInviteLinkRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getVideoChatInviteLink#acde7487 to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode getVideoChatInviteLink#acde7487: field group_call_id: %w", err)
		}
		g.GroupCallID = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode getVideoChatInviteLink#acde7487: field can_self_unmute: %w", err)
		}
		g.CanSelfUnmute = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetVideoChatInviteLinkRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getVideoChatInviteLink#acde7487 as nil")
	}
	b.ObjStart()
	b.PutID("getVideoChatInviteLink")
	b.Comma()
	b.FieldStart("group_call_id")
	b.PutInt32(g.GroupCallID)
	b.Comma()
	b.FieldStart("can_self_unmute")
	b.PutBool(g.CanSelfUnmute)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (g *GetVideoChatInviteLinkRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if g == nil {
		return fmt.Errorf("can't decode getVideoChatInviteLink#acde7487 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("getVideoChatInviteLink"); err != nil {
				return fmt.Errorf("unable to decode getVideoChatInviteLink#acde7487: %w", err)
			}
		case "group_call_id":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode getVideoChatInviteLink#acde7487: field group_call_id: %w", err)
			}
			g.GroupCallID = value
		case "can_self_unmute":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode getVideoChatInviteLink#acde7487: field can_self_unmute: %w", err)
			}
			g.CanSelfUnmute = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetGroupCallID returns value of GroupCallID field.
func (g *GetVideoChatInviteLinkRequest) GetGroupCallID() (value int32) {
	if g == nil {
		return
	}
	return g.GroupCallID
}

// GetCanSelfUnmute returns value of CanSelfUnmute field.
func (g *GetVideoChatInviteLinkRequest) GetCanSelfUnmute() (value bool) {
	if g == nil {
		return
	}
	return g.CanSelfUnmute
}

// GetVideoChatInviteLink invokes method getVideoChatInviteLink#acde7487 returning error if any.
func (c *Client) GetVideoChatInviteLink(ctx context.Context, request *GetVideoChatInviteLinkRequest) (*HTTPURL, error) {
	var result HTTPURL

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