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

// StartGroupCallRecordingRequest represents TL type `startGroupCallRecording#68c5847b`.
type StartGroupCallRecordingRequest struct {
	// Group call identifier
	GroupCallID int32
	// Group call recording title; 0-64 characters
	Title string
	// Pass true to record a video file instead of an audio file
	RecordVideo bool
	// Pass true to use portrait orientation for video instead of landscape one
	UsePortraitOrientation bool
}

// StartGroupCallRecordingRequestTypeID is TL type id of StartGroupCallRecordingRequest.
const StartGroupCallRecordingRequestTypeID = 0x68c5847b

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

func (s *StartGroupCallRecordingRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.GroupCallID == 0) {
		return false
	}
	if !(s.Title == "") {
		return false
	}
	if !(s.RecordVideo == false) {
		return false
	}
	if !(s.UsePortraitOrientation == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *StartGroupCallRecordingRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "startGroupCallRecording",
		ID:   StartGroupCallRecordingRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "GroupCallID",
			SchemaName: "group_call_id",
		},
		{
			Name:       "Title",
			SchemaName: "title",
		},
		{
			Name:       "RecordVideo",
			SchemaName: "record_video",
		},
		{
			Name:       "UsePortraitOrientation",
			SchemaName: "use_portrait_orientation",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *StartGroupCallRecordingRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode startGroupCallRecording#68c5847b as nil")
	}
	b.PutID(StartGroupCallRecordingRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *StartGroupCallRecordingRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode startGroupCallRecording#68c5847b as nil")
	}
	b.PutInt32(s.GroupCallID)
	b.PutString(s.Title)
	b.PutBool(s.RecordVideo)
	b.PutBool(s.UsePortraitOrientation)
	return nil
}

// Decode implements bin.Decoder.
func (s *StartGroupCallRecordingRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode startGroupCallRecording#68c5847b to nil")
	}
	if err := b.ConsumeID(StartGroupCallRecordingRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode startGroupCallRecording#68c5847b: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *StartGroupCallRecordingRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode startGroupCallRecording#68c5847b to nil")
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode startGroupCallRecording#68c5847b: field group_call_id: %w", err)
		}
		s.GroupCallID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode startGroupCallRecording#68c5847b: field title: %w", err)
		}
		s.Title = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode startGroupCallRecording#68c5847b: field record_video: %w", err)
		}
		s.RecordVideo = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode startGroupCallRecording#68c5847b: field use_portrait_orientation: %w", err)
		}
		s.UsePortraitOrientation = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *StartGroupCallRecordingRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode startGroupCallRecording#68c5847b as nil")
	}
	b.ObjStart()
	b.PutID("startGroupCallRecording")
	b.Comma()
	b.FieldStart("group_call_id")
	b.PutInt32(s.GroupCallID)
	b.Comma()
	b.FieldStart("title")
	b.PutString(s.Title)
	b.Comma()
	b.FieldStart("record_video")
	b.PutBool(s.RecordVideo)
	b.Comma()
	b.FieldStart("use_portrait_orientation")
	b.PutBool(s.UsePortraitOrientation)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *StartGroupCallRecordingRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode startGroupCallRecording#68c5847b to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("startGroupCallRecording"); err != nil {
				return fmt.Errorf("unable to decode startGroupCallRecording#68c5847b: %w", err)
			}
		case "group_call_id":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode startGroupCallRecording#68c5847b: field group_call_id: %w", err)
			}
			s.GroupCallID = value
		case "title":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode startGroupCallRecording#68c5847b: field title: %w", err)
			}
			s.Title = value
		case "record_video":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode startGroupCallRecording#68c5847b: field record_video: %w", err)
			}
			s.RecordVideo = value
		case "use_portrait_orientation":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode startGroupCallRecording#68c5847b: field use_portrait_orientation: %w", err)
			}
			s.UsePortraitOrientation = value
		default:
			return b.Skip()
		}
		return nil
	})
}

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

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

// GetRecordVideo returns value of RecordVideo field.
func (s *StartGroupCallRecordingRequest) GetRecordVideo() (value bool) {
	if s == nil {
		return
	}
	return s.RecordVideo
}

// GetUsePortraitOrientation returns value of UsePortraitOrientation field.
func (s *StartGroupCallRecordingRequest) GetUsePortraitOrientation() (value bool) {
	if s == nil {
		return
	}
	return s.UsePortraitOrientation
}

// StartGroupCallRecording invokes method startGroupCallRecording#68c5847b returning error if any.
func (c *Client) StartGroupCallRecording(ctx context.Context, request *StartGroupCallRecordingRequest) error {
	var ok Ok

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