// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// SecureSecretSettings represents TL type `secureSecretSettings#1527bcac`.
// Secure settings
//
// See https://core.telegram.org/constructor/secureSecretSettings for reference.
type SecureSecretSettings struct {
	// Secure KDF algo
	SecureAlgo SecurePasswordKdfAlgoClass
	// Secure secret
	SecureSecret []byte
	// Secret ID
	SecureSecretID int64
}

// SecureSecretSettingsTypeID is TL type id of SecureSecretSettings.
const SecureSecretSettingsTypeID = 0x1527bcac

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

func (s *SecureSecretSettings) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.SecureAlgo == nil) {
		return false
	}
	if !(s.SecureSecret == nil) {
		return false
	}
	if !(s.SecureSecretID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills SecureSecretSettings from given interface.
func (s *SecureSecretSettings) FillFrom(from interface {
	GetSecureAlgo() (value SecurePasswordKdfAlgoClass)
	GetSecureSecret() (value []byte)
	GetSecureSecretID() (value int64)
}) {
	s.SecureAlgo = from.GetSecureAlgo()
	s.SecureSecret = from.GetSecureSecret()
	s.SecureSecretID = from.GetSecureSecretID()
}

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

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

// TypeInfo returns info about TL type.
func (s *SecureSecretSettings) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "secureSecretSettings",
		ID:   SecureSecretSettingsTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "SecureAlgo",
			SchemaName: "secure_algo",
		},
		{
			Name:       "SecureSecret",
			SchemaName: "secure_secret",
		},
		{
			Name:       "SecureSecretID",
			SchemaName: "secure_secret_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SecureSecretSettings) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode secureSecretSettings#1527bcac as nil")
	}
	b.PutID(SecureSecretSettingsTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SecureSecretSettings) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode secureSecretSettings#1527bcac as nil")
	}
	if s.SecureAlgo == nil {
		return fmt.Errorf("unable to encode secureSecretSettings#1527bcac: field secure_algo is nil")
	}
	if err := s.SecureAlgo.Encode(b); err != nil {
		return fmt.Errorf("unable to encode secureSecretSettings#1527bcac: field secure_algo: %w", err)
	}
	b.PutBytes(s.SecureSecret)
	b.PutLong(s.SecureSecretID)
	return nil
}

// Decode implements bin.Decoder.
func (s *SecureSecretSettings) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode secureSecretSettings#1527bcac to nil")
	}
	if err := b.ConsumeID(SecureSecretSettingsTypeID); err != nil {
		return fmt.Errorf("unable to decode secureSecretSettings#1527bcac: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SecureSecretSettings) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode secureSecretSettings#1527bcac to nil")
	}
	{
		value, err := DecodeSecurePasswordKdfAlgo(b)
		if err != nil {
			return fmt.Errorf("unable to decode secureSecretSettings#1527bcac: field secure_algo: %w", err)
		}
		s.SecureAlgo = value
	}
	{
		value, err := b.Bytes()
		if err != nil {
			return fmt.Errorf("unable to decode secureSecretSettings#1527bcac: field secure_secret: %w", err)
		}
		s.SecureSecret = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode secureSecretSettings#1527bcac: field secure_secret_id: %w", err)
		}
		s.SecureSecretID = value
	}
	return nil
}

// GetSecureAlgo returns value of SecureAlgo field.
func (s *SecureSecretSettings) GetSecureAlgo() (value SecurePasswordKdfAlgoClass) {
	if s == nil {
		return
	}
	return s.SecureAlgo
}

// GetSecureSecret returns value of SecureSecret field.
func (s *SecureSecretSettings) GetSecureSecret() (value []byte) {
	if s == nil {
		return
	}
	return s.SecureSecret
}

// GetSecureSecretID returns value of SecureSecretID field.
func (s *SecureSecretSettings) GetSecureSecretID() (value int64) {
	if s == nil {
		return
	}
	return s.SecureSecretID
}
