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

// SetBusinessAccountProfilePhotoRequest represents TL type `setBusinessAccountProfilePhoto#460088d5`.
type SetBusinessAccountProfilePhotoRequest struct {
	// Unique identifier of business connection
	BusinessConnectionID string
	// Profile photo to set; pass null to remove the photo
	Photo InputChatPhotoClass
	// Pass true to set the public photo, which will be visible even the main photo is hidden
	// by privacy settings
	IsPublic bool
}

// SetBusinessAccountProfilePhotoRequestTypeID is TL type id of SetBusinessAccountProfilePhotoRequest.
const SetBusinessAccountProfilePhotoRequestTypeID = 0x460088d5

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

func (s *SetBusinessAccountProfilePhotoRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.BusinessConnectionID == "") {
		return false
	}
	if !(s.Photo == nil) {
		return false
	}
	if !(s.IsPublic == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetBusinessAccountProfilePhotoRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setBusinessAccountProfilePhoto",
		ID:   SetBusinessAccountProfilePhotoRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "BusinessConnectionID",
			SchemaName: "business_connection_id",
		},
		{
			Name:       "Photo",
			SchemaName: "photo",
		},
		{
			Name:       "IsPublic",
			SchemaName: "is_public",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetBusinessAccountProfilePhotoRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setBusinessAccountProfilePhoto#460088d5 as nil")
	}
	b.PutID(SetBusinessAccountProfilePhotoRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetBusinessAccountProfilePhotoRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setBusinessAccountProfilePhoto#460088d5 as nil")
	}
	b.PutString(s.BusinessConnectionID)
	if s.Photo == nil {
		return fmt.Errorf("unable to encode setBusinessAccountProfilePhoto#460088d5: field photo is nil")
	}
	if err := s.Photo.Encode(b); err != nil {
		return fmt.Errorf("unable to encode setBusinessAccountProfilePhoto#460088d5: field photo: %w", err)
	}
	b.PutBool(s.IsPublic)
	return nil
}

// Decode implements bin.Decoder.
func (s *SetBusinessAccountProfilePhotoRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setBusinessAccountProfilePhoto#460088d5 to nil")
	}
	if err := b.ConsumeID(SetBusinessAccountProfilePhotoRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode setBusinessAccountProfilePhoto#460088d5: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SetBusinessAccountProfilePhotoRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setBusinessAccountProfilePhoto#460088d5 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode setBusinessAccountProfilePhoto#460088d5: field business_connection_id: %w", err)
		}
		s.BusinessConnectionID = value
	}
	{
		value, err := DecodeInputChatPhoto(b)
		if err != nil {
			return fmt.Errorf("unable to decode setBusinessAccountProfilePhoto#460088d5: field photo: %w", err)
		}
		s.Photo = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode setBusinessAccountProfilePhoto#460088d5: field is_public: %w", err)
		}
		s.IsPublic = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetBusinessAccountProfilePhotoRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setBusinessAccountProfilePhoto#460088d5 as nil")
	}
	b.ObjStart()
	b.PutID("setBusinessAccountProfilePhoto")
	b.Comma()
	b.FieldStart("business_connection_id")
	b.PutString(s.BusinessConnectionID)
	b.Comma()
	b.FieldStart("photo")
	if s.Photo == nil {
		return fmt.Errorf("unable to encode setBusinessAccountProfilePhoto#460088d5: field photo is nil")
	}
	if err := s.Photo.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode setBusinessAccountProfilePhoto#460088d5: field photo: %w", err)
	}
	b.Comma()
	b.FieldStart("is_public")
	b.PutBool(s.IsPublic)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SetBusinessAccountProfilePhotoRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode setBusinessAccountProfilePhoto#460088d5 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("setBusinessAccountProfilePhoto"); err != nil {
				return fmt.Errorf("unable to decode setBusinessAccountProfilePhoto#460088d5: %w", err)
			}
		case "business_connection_id":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode setBusinessAccountProfilePhoto#460088d5: field business_connection_id: %w", err)
			}
			s.BusinessConnectionID = value
		case "photo":
			value, err := DecodeTDLibJSONInputChatPhoto(b)
			if err != nil {
				return fmt.Errorf("unable to decode setBusinessAccountProfilePhoto#460088d5: field photo: %w", err)
			}
			s.Photo = value
		case "is_public":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode setBusinessAccountProfilePhoto#460088d5: field is_public: %w", err)
			}
			s.IsPublic = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetBusinessConnectionID returns value of BusinessConnectionID field.
func (s *SetBusinessAccountProfilePhotoRequest) GetBusinessConnectionID() (value string) {
	if s == nil {
		return
	}
	return s.BusinessConnectionID
}

// GetPhoto returns value of Photo field.
func (s *SetBusinessAccountProfilePhotoRequest) GetPhoto() (value InputChatPhotoClass) {
	if s == nil {
		return
	}
	return s.Photo
}

// GetIsPublic returns value of IsPublic field.
func (s *SetBusinessAccountProfilePhotoRequest) GetIsPublic() (value bool) {
	if s == nil {
		return
	}
	return s.IsPublic
}

// SetBusinessAccountProfilePhoto invokes method setBusinessAccountProfilePhoto#460088d5 returning error if any.
func (c *Client) SetBusinessAccountProfilePhoto(ctx context.Context, request *SetBusinessAccountProfilePhotoRequest) error {
	var ok Ok

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