// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	
	
	
	
	

	

	
	
	
	
)

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

// WallPaper represents TL type `wallPaper#a437c3ed`.
// Represents a wallpaper¹ based on an image.
//
// Links:
//  1. https://core.telegram.org/api/wallpapers
//
// See https://core.telegram.org/constructor/wallPaper for reference.
type WallPaper struct {
	// Identifier
	ID int64
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether we created this wallpaper
	Creator bool
	// Whether this is the default wallpaper
	Default bool
	// Whether this is a pattern wallpaper »¹
	//
	// Links:
	//  1) https://core.telegram.org/api/wallpapers#pattern-wallpapers
	Pattern bool
	// Whether this wallpaper should be used in dark mode.
	Dark bool
	// Access hash
	AccessHash int64
	// Unique wallpaper ID, used when generating wallpaper links¹ or importing wallpaper
	// links².
	//
	// Links:
	//  1) https://core.telegram.org/api/links#wallpaper-links
	//  2) https://core.telegram.org/api/wallpapers
	Slug string
	// The actual wallpaper
	Document DocumentClass
	// Info on how to generate the wallpaper, according to these instructions »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/wallpapers
	//
	// Use SetSettings and GetSettings helpers.
	Settings WallPaperSettings
}

// WallPaperTypeID is TL type id of WallPaper.
const WallPaperTypeID = 0xa437c3ed

// construct implements constructor of WallPaperClass.
func ( WallPaper) () WallPaperClass { return & }

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

	_ WallPaperClass = &WallPaper{}
)

func ( *WallPaper) () bool {
	if  == nil {
		return true
	}
	if !(.ID == 0) {
		return false
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Creator == false) {
		return false
	}
	if !(.Default == false) {
		return false
	}
	if !(.Pattern == false) {
		return false
	}
	if !(.Dark == false) {
		return false
	}
	if !(.AccessHash == 0) {
		return false
	}
	if !(.Slug == "") {
		return false
	}
	if !(.Document == nil) {
		return false
	}
	if !(.Settings.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills WallPaper from given interface.
func ( *WallPaper) ( interface {
	() ( int64)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( int64)
	() ( string)
	() ( DocumentClass)
	() ( WallPaperSettings,  bool)
}) {
	.ID = .()
	.Creator = .()
	.Default = .()
	.Pattern = .()
	.Dark = .()
	.AccessHash = .()
	.Slug = .()
	.Document = .()
	if ,  := .();  {
		.Settings = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *WallPaper) () tdp.Type {
	 := tdp.Type{
		Name: "wallPaper",
		ID:   WallPaperTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "Creator",
			SchemaName: "creator",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Default",
			SchemaName: "default",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Pattern",
			SchemaName: "pattern",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Dark",
			SchemaName: "dark",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "AccessHash",
			SchemaName: "access_hash",
		},
		{
			Name:       "Slug",
			SchemaName: "slug",
		},
		{
			Name:       "Document",
			SchemaName: "document",
		},
		{
			Name:       "Settings",
			SchemaName: "settings",
			Null:       !.Flags.Has(2),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *WallPaper) () {
	if !(.Creator == false) {
		.Flags.Set(0)
	}
	if !(.Default == false) {
		.Flags.Set(1)
	}
	if !(.Pattern == false) {
		.Flags.Set(3)
	}
	if !(.Dark == false) {
		.Flags.Set(4)
	}
	if !(.Settings.Zero()) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *WallPaper) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode wallPaper#a437c3ed as nil")
	}
	.PutID(WallPaperTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *WallPaper) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode wallPaper#a437c3ed as nil")
	}
	.SetFlags()
	.PutLong(.ID)
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode wallPaper#a437c3ed: field flags: %w", )
	}
	.PutLong(.AccessHash)
	.PutString(.Slug)
	if .Document == nil {
		return fmt.Errorf("unable to encode wallPaper#a437c3ed: field document is nil")
	}
	if  := .Document.Encode();  != nil {
		return fmt.Errorf("unable to encode wallPaper#a437c3ed: field document: %w", )
	}
	if .Flags.Has(2) {
		if  := .Settings.Encode();  != nil {
			return fmt.Errorf("unable to encode wallPaper#a437c3ed: field settings: %w", )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *WallPaper) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode wallPaper#a437c3ed to nil")
	}
	if  := .ConsumeID(WallPaperTypeID);  != nil {
		return fmt.Errorf("unable to decode wallPaper#a437c3ed: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *WallPaper) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode wallPaper#a437c3ed to nil")
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode wallPaper#a437c3ed: field id: %w", )
		}
		.ID = 
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode wallPaper#a437c3ed: field flags: %w", )
		}
	}
	.Creator = .Flags.Has(0)
	.Default = .Flags.Has(1)
	.Pattern = .Flags.Has(3)
	.Dark = .Flags.Has(4)
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode wallPaper#a437c3ed: field access_hash: %w", )
		}
		.AccessHash = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode wallPaper#a437c3ed: field slug: %w", )
		}
		.Slug = 
	}
	{
		,  := DecodeDocument()
		if  != nil {
			return fmt.Errorf("unable to decode wallPaper#a437c3ed: field document: %w", )
		}
		.Document = 
	}
	if .Flags.Has(2) {
		if  := .Settings.Decode();  != nil {
			return fmt.Errorf("unable to decode wallPaper#a437c3ed: field settings: %w", )
		}
	}
	return nil
}

// GetID returns value of ID field.
func ( *WallPaper) () ( int64) {
	if  == nil {
		return
	}
	return .ID
}

// SetCreator sets value of Creator conditional field.
func ( *WallPaper) ( bool) {
	if  {
		.Flags.Set(0)
		.Creator = true
	} else {
		.Flags.Unset(0)
		.Creator = false
	}
}

// GetCreator returns value of Creator conditional field.
func ( *WallPaper) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetDefault sets value of Default conditional field.
func ( *WallPaper) ( bool) {
	if  {
		.Flags.Set(1)
		.Default = true
	} else {
		.Flags.Unset(1)
		.Default = false
	}
}

// GetDefault returns value of Default conditional field.
func ( *WallPaper) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetPattern sets value of Pattern conditional field.
func ( *WallPaper) ( bool) {
	if  {
		.Flags.Set(3)
		.Pattern = true
	} else {
		.Flags.Unset(3)
		.Pattern = false
	}
}

// GetPattern returns value of Pattern conditional field.
func ( *WallPaper) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(3)
}

// SetDark sets value of Dark conditional field.
func ( *WallPaper) ( bool) {
	if  {
		.Flags.Set(4)
		.Dark = true
	} else {
		.Flags.Unset(4)
		.Dark = false
	}
}

// GetDark returns value of Dark conditional field.
func ( *WallPaper) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(4)
}

// GetAccessHash returns value of AccessHash field.
func ( *WallPaper) () ( int64) {
	if  == nil {
		return
	}
	return .AccessHash
}

// GetSlug returns value of Slug field.
func ( *WallPaper) () ( string) {
	if  == nil {
		return
	}
	return .Slug
}

// GetDocument returns value of Document field.
func ( *WallPaper) () ( DocumentClass) {
	if  == nil {
		return
	}
	return .Document
}

// SetSettings sets value of Settings conditional field.
func ( *WallPaper) ( WallPaperSettings) {
	.Flags.Set(2)
	.Settings = 
}

// GetSettings returns value of Settings conditional field and
// boolean which is true if field was set.
func ( *WallPaper) () ( WallPaperSettings,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .Settings, true
}

// WallPaperNoFile represents TL type `wallPaperNoFile#e0804116`.
// Represents a wallpaper¹ only based on colors/gradients.
//
// Links:
//  1. https://core.telegram.org/api/wallpapers
//
// See https://core.telegram.org/constructor/wallPaperNoFile for reference.
type WallPaperNoFile struct {
	// Wallpaper ID
	ID int64
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether this is the default wallpaper
	Default bool
	// Whether this wallpaper should be used in dark mode.
	Dark bool
	// Info on how to generate the wallpaper.
	//
	// Use SetSettings and GetSettings helpers.
	Settings WallPaperSettings
}

// WallPaperNoFileTypeID is TL type id of WallPaperNoFile.
const WallPaperNoFileTypeID = 0xe0804116

// construct implements constructor of WallPaperClass.
func ( WallPaperNoFile) () WallPaperClass { return & }

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

	_ WallPaperClass = &WallPaperNoFile{}
)

func ( *WallPaperNoFile) () bool {
	if  == nil {
		return true
	}
	if !(.ID == 0) {
		return false
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Default == false) {
		return false
	}
	if !(.Dark == false) {
		return false
	}
	if !(.Settings.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills WallPaperNoFile from given interface.
func ( *WallPaperNoFile) ( interface {
	() ( int64)
	() ( bool)
	() ( bool)
	() ( WallPaperSettings,  bool)
}) {
	.ID = .()
	.Default = .()
	.Dark = .()
	if ,  := .();  {
		.Settings = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *WallPaperNoFile) () tdp.Type {
	 := tdp.Type{
		Name: "wallPaperNoFile",
		ID:   WallPaperNoFileTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "Default",
			SchemaName: "default",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Dark",
			SchemaName: "dark",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "Settings",
			SchemaName: "settings",
			Null:       !.Flags.Has(2),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *WallPaperNoFile) () {
	if !(.Default == false) {
		.Flags.Set(1)
	}
	if !(.Dark == false) {
		.Flags.Set(4)
	}
	if !(.Settings.Zero()) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *WallPaperNoFile) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode wallPaperNoFile#e0804116 as nil")
	}
	.PutID(WallPaperNoFileTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *WallPaperNoFile) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode wallPaperNoFile#e0804116 as nil")
	}
	.SetFlags()
	.PutLong(.ID)
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode wallPaperNoFile#e0804116: field flags: %w", )
	}
	if .Flags.Has(2) {
		if  := .Settings.Encode();  != nil {
			return fmt.Errorf("unable to encode wallPaperNoFile#e0804116: field settings: %w", )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *WallPaperNoFile) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode wallPaperNoFile#e0804116 to nil")
	}
	if  := .ConsumeID(WallPaperNoFileTypeID);  != nil {
		return fmt.Errorf("unable to decode wallPaperNoFile#e0804116: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *WallPaperNoFile) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode wallPaperNoFile#e0804116 to nil")
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode wallPaperNoFile#e0804116: field id: %w", )
		}
		.ID = 
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode wallPaperNoFile#e0804116: field flags: %w", )
		}
	}
	.Default = .Flags.Has(1)
	.Dark = .Flags.Has(4)
	if .Flags.Has(2) {
		if  := .Settings.Decode();  != nil {
			return fmt.Errorf("unable to decode wallPaperNoFile#e0804116: field settings: %w", )
		}
	}
	return nil
}

// GetID returns value of ID field.
func ( *WallPaperNoFile) () ( int64) {
	if  == nil {
		return
	}
	return .ID
}

// SetDefault sets value of Default conditional field.
func ( *WallPaperNoFile) ( bool) {
	if  {
		.Flags.Set(1)
		.Default = true
	} else {
		.Flags.Unset(1)
		.Default = false
	}
}

// GetDefault returns value of Default conditional field.
func ( *WallPaperNoFile) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetDark sets value of Dark conditional field.
func ( *WallPaperNoFile) ( bool) {
	if  {
		.Flags.Set(4)
		.Dark = true
	} else {
		.Flags.Unset(4)
		.Dark = false
	}
}

// GetDark returns value of Dark conditional field.
func ( *WallPaperNoFile) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(4)
}

// SetSettings sets value of Settings conditional field.
func ( *WallPaperNoFile) ( WallPaperSettings) {
	.Flags.Set(2)
	.Settings = 
}

// GetSettings returns value of Settings conditional field and
// boolean which is true if field was set.
func ( *WallPaperNoFile) () ( WallPaperSettings,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .Settings, true
}

// WallPaperClassName is schema name of WallPaperClass.
const WallPaperClassName = "WallPaper"

// WallPaperClass represents WallPaper generic type.
//
// See https://core.telegram.org/type/WallPaper for reference.
//
// Example:
//
//	g, err := tg.DecodeWallPaper(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.WallPaper: // wallPaper#a437c3ed
//	case *tg.WallPaperNoFile: // wallPaperNoFile#e0804116
//	default: panic(v)
//	}
type WallPaperClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() WallPaperClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	// Identifier
	GetID() (value int64)

	// Whether this is the default wallpaper
	GetDefault() (value bool)

	// Whether this wallpaper should be used in dark mode.
	GetDark() (value bool)

	// Info on how to generate the wallpaper, according to these instructions »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/wallpapers
	GetSettings() (value WallPaperSettings, ok bool)
}

// AsInput tries to map WallPaper to InputWallPaper.
func ( *WallPaper) () *InputWallPaper {
	 := new(InputWallPaper)
	.ID = .GetID()
	.AccessHash = .GetAccessHash()

	return 
}

// AsInputWallPaperSlug tries to map WallPaper to InputWallPaperSlug.
func ( *WallPaper) () *InputWallPaperSlug {
	 := new(InputWallPaperSlug)
	.Slug = .GetSlug()

	return 
}

// AsInputWallPaperNoFile tries to map WallPaper to InputWallPaperNoFile.
func ( *WallPaper) () *InputWallPaperNoFile {
	 := new(InputWallPaperNoFile)
	.ID = .GetID()

	return 
}

// AsInput tries to map WallPaperNoFile to InputWallPaperNoFile.
func ( *WallPaperNoFile) () *InputWallPaperNoFile {
	 := new(InputWallPaperNoFile)
	.ID = .GetID()

	return 
}

// DecodeWallPaper implements binary de-serialization for WallPaperClass.
func ( *bin.Buffer) (WallPaperClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case WallPaperTypeID:
		// Decoding wallPaper#a437c3ed.
		 := WallPaper{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode WallPaperClass: %w", )
		}
		return &, nil
	case WallPaperNoFileTypeID:
		// Decoding wallPaperNoFile#e0804116.
		 := WallPaperNoFile{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode WallPaperClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode WallPaperClass: %w", bin.NewUnexpectedID())
	}
}

// WallPaper boxes the WallPaperClass providing a helper.
type WallPaperBox struct {
	WallPaper WallPaperClass
}

// Decode implements bin.Decoder for WallPaperBox.
func ( *WallPaperBox) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("unable to decode WallPaperBox to nil")
	}
	,  := DecodeWallPaper()
	if  != nil {
		return fmt.Errorf("unable to decode boxed value: %w", )
	}
	.WallPaper = 
	return nil
}

// Encode implements bin.Encode for WallPaperBox.
func ( *WallPaperBox) ( *bin.Buffer) error {
	if  == nil || .WallPaper == nil {
		return fmt.Errorf("unable to encode WallPaperClass as nil")
	}
	return .WallPaper.Encode()
}