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

// ArchiveChatListSettings represents TL type `archiveChatListSettings#3f176aa4`.
type ArchiveChatListSettings struct {
	// True, if new chats from non-contacts will be automatically archived and muted. Can be
	// set to true only if the option "can_archive_and_mute_new_chats_from_unknown_users" is
	// true
	ArchiveAndMuteNewChatsFromUnknownUsers bool
	// True, if unmuted chats will be kept in the Archive chat list when they get a new
	// message
	KeepUnmutedChatsArchived bool
	// True, if unmuted chats, that are always included or pinned in a folder, will be kept
	// in the Archive chat list when they get a new message. Ignored if
	// keep_unmuted_chats_archived == true
	KeepChatsFromFoldersArchived bool
}

// ArchiveChatListSettingsTypeID is TL type id of ArchiveChatListSettings.
const ArchiveChatListSettingsTypeID = 0x3f176aa4

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

func (a *ArchiveChatListSettings) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.ArchiveAndMuteNewChatsFromUnknownUsers == false) {
		return false
	}
	if !(a.KeepUnmutedChatsArchived == false) {
		return false
	}
	if !(a.KeepChatsFromFoldersArchived == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (a *ArchiveChatListSettings) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "archiveChatListSettings",
		ID:   ArchiveChatListSettingsTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ArchiveAndMuteNewChatsFromUnknownUsers",
			SchemaName: "archive_and_mute_new_chats_from_unknown_users",
		},
		{
			Name:       "KeepUnmutedChatsArchived",
			SchemaName: "keep_unmuted_chats_archived",
		},
		{
			Name:       "KeepChatsFromFoldersArchived",
			SchemaName: "keep_chats_from_folders_archived",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *ArchiveChatListSettings) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode archiveChatListSettings#3f176aa4 as nil")
	}
	b.PutID(ArchiveChatListSettingsTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *ArchiveChatListSettings) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode archiveChatListSettings#3f176aa4 as nil")
	}
	b.PutBool(a.ArchiveAndMuteNewChatsFromUnknownUsers)
	b.PutBool(a.KeepUnmutedChatsArchived)
	b.PutBool(a.KeepChatsFromFoldersArchived)
	return nil
}

// Decode implements bin.Decoder.
func (a *ArchiveChatListSettings) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode archiveChatListSettings#3f176aa4 to nil")
	}
	if err := b.ConsumeID(ArchiveChatListSettingsTypeID); err != nil {
		return fmt.Errorf("unable to decode archiveChatListSettings#3f176aa4: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *ArchiveChatListSettings) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode archiveChatListSettings#3f176aa4 to nil")
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode archiveChatListSettings#3f176aa4: field archive_and_mute_new_chats_from_unknown_users: %w", err)
		}
		a.ArchiveAndMuteNewChatsFromUnknownUsers = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode archiveChatListSettings#3f176aa4: field keep_unmuted_chats_archived: %w", err)
		}
		a.KeepUnmutedChatsArchived = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode archiveChatListSettings#3f176aa4: field keep_chats_from_folders_archived: %w", err)
		}
		a.KeepChatsFromFoldersArchived = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (a *ArchiveChatListSettings) EncodeTDLibJSON(b tdjson.Encoder) error {
	if a == nil {
		return fmt.Errorf("can't encode archiveChatListSettings#3f176aa4 as nil")
	}
	b.ObjStart()
	b.PutID("archiveChatListSettings")
	b.Comma()
	b.FieldStart("archive_and_mute_new_chats_from_unknown_users")
	b.PutBool(a.ArchiveAndMuteNewChatsFromUnknownUsers)
	b.Comma()
	b.FieldStart("keep_unmuted_chats_archived")
	b.PutBool(a.KeepUnmutedChatsArchived)
	b.Comma()
	b.FieldStart("keep_chats_from_folders_archived")
	b.PutBool(a.KeepChatsFromFoldersArchived)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (a *ArchiveChatListSettings) DecodeTDLibJSON(b tdjson.Decoder) error {
	if a == nil {
		return fmt.Errorf("can't decode archiveChatListSettings#3f176aa4 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("archiveChatListSettings"); err != nil {
				return fmt.Errorf("unable to decode archiveChatListSettings#3f176aa4: %w", err)
			}
		case "archive_and_mute_new_chats_from_unknown_users":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode archiveChatListSettings#3f176aa4: field archive_and_mute_new_chats_from_unknown_users: %w", err)
			}
			a.ArchiveAndMuteNewChatsFromUnknownUsers = value
		case "keep_unmuted_chats_archived":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode archiveChatListSettings#3f176aa4: field keep_unmuted_chats_archived: %w", err)
			}
			a.KeepUnmutedChatsArchived = value
		case "keep_chats_from_folders_archived":
			value, err := b.Bool()
			if err != nil {
				return fmt.Errorf("unable to decode archiveChatListSettings#3f176aa4: field keep_chats_from_folders_archived: %w", err)
			}
			a.KeepChatsFromFoldersArchived = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetArchiveAndMuteNewChatsFromUnknownUsers returns value of ArchiveAndMuteNewChatsFromUnknownUsers field.
func (a *ArchiveChatListSettings) GetArchiveAndMuteNewChatsFromUnknownUsers() (value bool) {
	if a == nil {
		return
	}
	return a.ArchiveAndMuteNewChatsFromUnknownUsers
}

// GetKeepUnmutedChatsArchived returns value of KeepUnmutedChatsArchived field.
func (a *ArchiveChatListSettings) GetKeepUnmutedChatsArchived() (value bool) {
	if a == nil {
		return
	}
	return a.KeepUnmutedChatsArchived
}

// GetKeepChatsFromFoldersArchived returns value of KeepChatsFromFoldersArchived field.
func (a *ArchiveChatListSettings) GetKeepChatsFromFoldersArchived() (value bool) {
	if a == nil {
		return
	}
	return a.KeepChatsFromFoldersArchived
}
