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

// ReportSponsoredChatRequest represents TL type `reportSponsoredChat#ca324d85`.
type ReportSponsoredChatRequest struct {
	// Unique identifier of the sponsored chat
	SponsoredChatUniqueID int64
	// Option identifier chosen by the user; leave empty for the initial request
	OptionID []byte
}

// ReportSponsoredChatRequestTypeID is TL type id of ReportSponsoredChatRequest.
const ReportSponsoredChatRequestTypeID = 0xca324d85

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

func (r *ReportSponsoredChatRequest) Zero() bool {
	if r == nil {
		return true
	}
	if !(r.SponsoredChatUniqueID == 0) {
		return false
	}
	if !(r.OptionID == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (r *ReportSponsoredChatRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "reportSponsoredChat",
		ID:   ReportSponsoredChatRequestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "SponsoredChatUniqueID",
			SchemaName: "sponsored_chat_unique_id",
		},
		{
			Name:       "OptionID",
			SchemaName: "option_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (r *ReportSponsoredChatRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode reportSponsoredChat#ca324d85 as nil")
	}
	b.PutID(ReportSponsoredChatRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *ReportSponsoredChatRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode reportSponsoredChat#ca324d85 as nil")
	}
	b.PutInt53(r.SponsoredChatUniqueID)
	b.PutBytes(r.OptionID)
	return nil
}

// Decode implements bin.Decoder.
func (r *ReportSponsoredChatRequest) Decode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode reportSponsoredChat#ca324d85 to nil")
	}
	if err := b.ConsumeID(ReportSponsoredChatRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode reportSponsoredChat#ca324d85: %w", err)
	}
	return r.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (r *ReportSponsoredChatRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode reportSponsoredChat#ca324d85 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode reportSponsoredChat#ca324d85: field sponsored_chat_unique_id: %w", err)
		}
		r.SponsoredChatUniqueID = value
	}
	{
		value, err := b.Bytes()
		if err != nil {
			return fmt.Errorf("unable to decode reportSponsoredChat#ca324d85: field option_id: %w", err)
		}
		r.OptionID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (r *ReportSponsoredChatRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if r == nil {
		return fmt.Errorf("can't encode reportSponsoredChat#ca324d85 as nil")
	}
	b.ObjStart()
	b.PutID("reportSponsoredChat")
	b.Comma()
	b.FieldStart("sponsored_chat_unique_id")
	b.PutInt53(r.SponsoredChatUniqueID)
	b.Comma()
	b.FieldStart("option_id")
	b.PutBytes(r.OptionID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (r *ReportSponsoredChatRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if r == nil {
		return fmt.Errorf("can't decode reportSponsoredChat#ca324d85 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("reportSponsoredChat"); err != nil {
				return fmt.Errorf("unable to decode reportSponsoredChat#ca324d85: %w", err)
			}
		case "sponsored_chat_unique_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode reportSponsoredChat#ca324d85: field sponsored_chat_unique_id: %w", err)
			}
			r.SponsoredChatUniqueID = value
		case "option_id":
			value, err := b.Bytes()
			if err != nil {
				return fmt.Errorf("unable to decode reportSponsoredChat#ca324d85: field option_id: %w", err)
			}
			r.OptionID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetSponsoredChatUniqueID returns value of SponsoredChatUniqueID field.
func (r *ReportSponsoredChatRequest) GetSponsoredChatUniqueID() (value int64) {
	if r == nil {
		return
	}
	return r.SponsoredChatUniqueID
}

// GetOptionID returns value of OptionID field.
func (r *ReportSponsoredChatRequest) GetOptionID() (value []byte) {
	if r == nil {
		return
	}
	return r.OptionID
}

// ReportSponsoredChat invokes method reportSponsoredChat#ca324d85 returning error if any.
func (c *Client) ReportSponsoredChat(ctx context.Context, request *ReportSponsoredChatRequest) (ReportSponsoredResultClass, error) {
	var result ReportSponsoredResultBox

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