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

// ContactBirthday represents TL type `contactBirthday#1d998733`.
// Birthday information of a contact.
//
// See https://core.telegram.org/constructor/contactBirthday for reference.
type ContactBirthday struct {
	// User ID.
	ContactID int64
	// Birthday information.
	Birthday Birthday
}

// ContactBirthdayTypeID is TL type id of ContactBirthday.
const ContactBirthdayTypeID = 0x1d998733

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

func (c *ContactBirthday) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.ContactID == 0) {
		return false
	}
	if !(c.Birthday.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills ContactBirthday from given interface.
func (c *ContactBirthday) FillFrom(from interface {
	GetContactID() (value int64)
	GetBirthday() (value Birthday)
}) {
	c.ContactID = from.GetContactID()
	c.Birthday = from.GetBirthday()
}

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

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

// TypeInfo returns info about TL type.
func (c *ContactBirthday) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "contactBirthday",
		ID:   ContactBirthdayTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ContactID",
			SchemaName: "contact_id",
		},
		{
			Name:       "Birthday",
			SchemaName: "birthday",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *ContactBirthday) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode contactBirthday#1d998733 as nil")
	}
	b.PutID(ContactBirthdayTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *ContactBirthday) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode contactBirthday#1d998733 as nil")
	}
	b.PutLong(c.ContactID)
	if err := c.Birthday.Encode(b); err != nil {
		return fmt.Errorf("unable to encode contactBirthday#1d998733: field birthday: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (c *ContactBirthday) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode contactBirthday#1d998733 to nil")
	}
	if err := b.ConsumeID(ContactBirthdayTypeID); err != nil {
		return fmt.Errorf("unable to decode contactBirthday#1d998733: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *ContactBirthday) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode contactBirthday#1d998733 to nil")
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode contactBirthday#1d998733: field contact_id: %w", err)
		}
		c.ContactID = value
	}
	{
		if err := c.Birthday.Decode(b); err != nil {
			return fmt.Errorf("unable to decode contactBirthday#1d998733: field birthday: %w", err)
		}
	}
	return nil
}

// GetContactID returns value of ContactID field.
func (c *ContactBirthday) GetContactID() (value int64) {
	if c == nil {
		return
	}
	return c.ContactID
}

// GetBirthday returns value of Birthday field.
func (c *ContactBirthday) GetBirthday() (value Birthday) {
	if c == nil {
		return
	}
	return c.Birthday
}
