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

// AccountReportProfilePhotoRequest represents TL type `account.reportProfilePhoto#fa8cc6f5`.
// Report a profile photo of a dialog
//
// See https://core.telegram.org/method/account.reportProfilePhoto for reference.
type AccountReportProfilePhotoRequest struct {
	// The dialog
	Peer InputPeerClass
	// Dialog photo ID
	PhotoID InputPhotoClass
	// Report reason
	Reason ReportReasonClass
	// Comment for report moderation
	Message string
}

// AccountReportProfilePhotoRequestTypeID is TL type id of AccountReportProfilePhotoRequest.
const AccountReportProfilePhotoRequestTypeID = 0xfa8cc6f5

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

func (r *AccountReportProfilePhotoRequest) Zero() bool {
	if r == nil {
		return true
	}
	if !(r.Peer == nil) {
		return false
	}
	if !(r.PhotoID == nil) {
		return false
	}
	if !(r.Reason == nil) {
		return false
	}
	if !(r.Message == "") {
		return false
	}

	return true
}

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

// FillFrom fills AccountReportProfilePhotoRequest from given interface.
func (r *AccountReportProfilePhotoRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetPhotoID() (value InputPhotoClass)
	GetReason() (value ReportReasonClass)
	GetMessage() (value string)
}) {
	r.Peer = from.GetPeer()
	r.PhotoID = from.GetPhotoID()
	r.Reason = from.GetReason()
	r.Message = from.GetMessage()
}

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

// TypeName returns name of type in TL schema.
func (*AccountReportProfilePhotoRequest) TypeName() string {
	return "account.reportProfilePhoto"
}

// TypeInfo returns info about TL type.
func (r *AccountReportProfilePhotoRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "account.reportProfilePhoto",
		ID:   AccountReportProfilePhotoRequestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "PhotoID",
			SchemaName: "photo_id",
		},
		{
			Name:       "Reason",
			SchemaName: "reason",
		},
		{
			Name:       "Message",
			SchemaName: "message",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (r *AccountReportProfilePhotoRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode account.reportProfilePhoto#fa8cc6f5 as nil")
	}
	b.PutID(AccountReportProfilePhotoRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *AccountReportProfilePhotoRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode account.reportProfilePhoto#fa8cc6f5 as nil")
	}
	if r.Peer == nil {
		return fmt.Errorf("unable to encode account.reportProfilePhoto#fa8cc6f5: field peer is nil")
	}
	if err := r.Peer.Encode(b); err != nil {
		return fmt.Errorf("unable to encode account.reportProfilePhoto#fa8cc6f5: field peer: %w", err)
	}
	if r.PhotoID == nil {
		return fmt.Errorf("unable to encode account.reportProfilePhoto#fa8cc6f5: field photo_id is nil")
	}
	if err := r.PhotoID.Encode(b); err != nil {
		return fmt.Errorf("unable to encode account.reportProfilePhoto#fa8cc6f5: field photo_id: %w", err)
	}
	if r.Reason == nil {
		return fmt.Errorf("unable to encode account.reportProfilePhoto#fa8cc6f5: field reason is nil")
	}
	if err := r.Reason.Encode(b); err != nil {
		return fmt.Errorf("unable to encode account.reportProfilePhoto#fa8cc6f5: field reason: %w", err)
	}
	b.PutString(r.Message)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (r *AccountReportProfilePhotoRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode account.reportProfilePhoto#fa8cc6f5 to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode account.reportProfilePhoto#fa8cc6f5: field peer: %w", err)
		}
		r.Peer = value
	}
	{
		value, err := DecodeInputPhoto(b)
		if err != nil {
			return fmt.Errorf("unable to decode account.reportProfilePhoto#fa8cc6f5: field photo_id: %w", err)
		}
		r.PhotoID = value
	}
	{
		value, err := DecodeReportReason(b)
		if err != nil {
			return fmt.Errorf("unable to decode account.reportProfilePhoto#fa8cc6f5: field reason: %w", err)
		}
		r.Reason = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode account.reportProfilePhoto#fa8cc6f5: field message: %w", err)
		}
		r.Message = value
	}
	return nil
}

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

// GetPhotoID returns value of PhotoID field.
func (r *AccountReportProfilePhotoRequest) GetPhotoID() (value InputPhotoClass) {
	if r == nil {
		return
	}
	return r.PhotoID
}

// GetReason returns value of Reason field.
func (r *AccountReportProfilePhotoRequest) GetReason() (value ReportReasonClass) {
	if r == nil {
		return
	}
	return r.Reason
}

// GetMessage returns value of Message field.
func (r *AccountReportProfilePhotoRequest) GetMessage() (value string) {
	if r == nil {
		return
	}
	return r.Message
}

// GetPhotoIDAsNotEmpty returns mapped value of PhotoID field.
func (r *AccountReportProfilePhotoRequest) GetPhotoIDAsNotEmpty() (*InputPhoto, bool) {
	return r.PhotoID.AsNotEmpty()
}

// AccountReportProfilePhoto invokes method account.reportProfilePhoto#fa8cc6f5 returning error if any.
// Report a profile photo of a dialog
//
// Possible errors:
//
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//
// See https://core.telegram.org/method/account.reportProfilePhoto for reference.
func (c *Client) AccountReportProfilePhoto(ctx context.Context, request *AccountReportProfilePhotoRequest) (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
}
