// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"github.com/gotd/td/bin"
	"github.com/gotd/td/tdjson"
	"github.com/gotd/td/tdp"
	"github.com/gotd/td/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{}
)

// MessagesUploadImportedMediaRequest represents TL type `messages.uploadImportedMedia#2a862092`.
// Upload a media file associated with an imported chat, click here for more info »¹.
//
// Links:
//  1. https://core.telegram.org/api/import
//
// See https://core.telegram.org/method/messages.uploadImportedMedia for reference.
type MessagesUploadImportedMediaRequest struct {
	// The Telegram chat where the media will be imported
	Peer InputPeerClass
	// Identifier of a history import session¹, returned by messages.initHistoryImport²
	//
	// Links:
	//  1) https://core.telegram.org/api/import
	//  2) https://core.telegram.org/method/messages.initHistoryImport
	ImportID int64
	// File name
	FileName string
	// Media metadata
	Media InputMediaClass
}

// MessagesUploadImportedMediaRequestTypeID is TL type id of MessagesUploadImportedMediaRequest.
const MessagesUploadImportedMediaRequestTypeID = 0x2a862092

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

func (u *MessagesUploadImportedMediaRequest) Zero() bool {
	if u == nil {
		return true
	}
	if !(u.Peer == nil) {
		return false
	}
	if !(u.ImportID == 0) {
		return false
	}
	if !(u.FileName == "") {
		return false
	}
	if !(u.Media == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesUploadImportedMediaRequest from given interface.
func (u *MessagesUploadImportedMediaRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetImportID() (value int64)
	GetFileName() (value string)
	GetMedia() (value InputMediaClass)
}) {
	u.Peer = from.GetPeer()
	u.ImportID = from.GetImportID()
	u.FileName = from.GetFileName()
	u.Media = from.GetMedia()
}

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

// TypeName returns name of type in TL schema.
func (*MessagesUploadImportedMediaRequest) TypeName() string {
	return "messages.uploadImportedMedia"
}

// TypeInfo returns info about TL type.
func (u *MessagesUploadImportedMediaRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.uploadImportedMedia",
		ID:   MessagesUploadImportedMediaRequestTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "ImportID",
			SchemaName: "import_id",
		},
		{
			Name:       "FileName",
			SchemaName: "file_name",
		},
		{
			Name:       "Media",
			SchemaName: "media",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (u *MessagesUploadImportedMediaRequest) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode messages.uploadImportedMedia#2a862092 as nil")
	}
	b.PutID(MessagesUploadImportedMediaRequestTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *MessagesUploadImportedMediaRequest) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode messages.uploadImportedMedia#2a862092 as nil")
	}
	if u.Peer == nil {
		return fmt.Errorf("unable to encode messages.uploadImportedMedia#2a862092: field peer is nil")
	}
	if err := u.Peer.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messages.uploadImportedMedia#2a862092: field peer: %w", err)
	}
	b.PutLong(u.ImportID)
	b.PutString(u.FileName)
	if u.Media == nil {
		return fmt.Errorf("unable to encode messages.uploadImportedMedia#2a862092: field media is nil")
	}
	if err := u.Media.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messages.uploadImportedMedia#2a862092: field media: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (u *MessagesUploadImportedMediaRequest) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode messages.uploadImportedMedia#2a862092 to nil")
	}
	if err := b.ConsumeID(MessagesUploadImportedMediaRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.uploadImportedMedia#2a862092: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *MessagesUploadImportedMediaRequest) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode messages.uploadImportedMedia#2a862092 to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode messages.uploadImportedMedia#2a862092: field peer: %w", err)
		}
		u.Peer = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode messages.uploadImportedMedia#2a862092: field import_id: %w", err)
		}
		u.ImportID = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messages.uploadImportedMedia#2a862092: field file_name: %w", err)
		}
		u.FileName = value
	}
	{
		value, err := DecodeInputMedia(b)
		if err != nil {
			return fmt.Errorf("unable to decode messages.uploadImportedMedia#2a862092: field media: %w", err)
		}
		u.Media = value
	}
	return nil
}

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

// GetImportID returns value of ImportID field.
func (u *MessagesUploadImportedMediaRequest) GetImportID() (value int64) {
	if u == nil {
		return
	}
	return u.ImportID
}

// GetFileName returns value of FileName field.
func (u *MessagesUploadImportedMediaRequest) GetFileName() (value string) {
	if u == nil {
		return
	}
	return u.FileName
}

// GetMedia returns value of Media field.
func (u *MessagesUploadImportedMediaRequest) GetMedia() (value InputMediaClass) {
	if u == nil {
		return
	}
	return u.Media
}

// MessagesUploadImportedMedia invokes method messages.uploadImportedMedia#2a862092 returning error if any.
// Upload a media file associated with an imported chat, click here for more info »¹.
//
// Links:
//  1. https://core.telegram.org/api/import
//
// See https://core.telegram.org/method/messages.uploadImportedMedia for reference.
func (c *Client) MessagesUploadImportedMedia(ctx context.Context, request *MessagesUploadImportedMediaRequest) (MessageMediaClass, error) {
	var result MessageMediaBox

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