// 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{} ) // ChatRevenueStatistics represents TL type `chatRevenueStatistics#636318bb`. type ChatRevenueStatistics struct { // A graph containing amount of revenue in a given hour RevenueByHourGraph StatisticalGraphClass // A graph containing amount of revenue RevenueGraph StatisticalGraphClass // Amount of earned revenue RevenueAmount ChatRevenueAmount // Current conversion rate of the cryptocurrency in which revenue is calculated to USD UsdRate float64 } // ChatRevenueStatisticsTypeID is TL type id of ChatRevenueStatistics. const ChatRevenueStatisticsTypeID = 0x636318bb // Ensuring interfaces in compile-time for ChatRevenueStatistics. var ( _ bin.Encoder = &ChatRevenueStatistics{} _ bin.Decoder = &ChatRevenueStatistics{} _ bin.BareEncoder = &ChatRevenueStatistics{} _ bin.BareDecoder = &ChatRevenueStatistics{} ) func (c *ChatRevenueStatistics) Zero() bool { if c == nil { return true } if !(c.RevenueByHourGraph == nil) { return false } if !(c.RevenueGraph == nil) { return false } if !(c.RevenueAmount.Zero()) { return false } if !(c.UsdRate == 0) { return false } return true } // String implements fmt.Stringer. func (c *ChatRevenueStatistics) String() string { if c == nil { return "ChatRevenueStatistics(nil)" } type Alias ChatRevenueStatistics return fmt.Sprintf("ChatRevenueStatistics%+v", Alias(*c)) } // TypeID returns type id in TL schema. // // See https://core.telegram.org/mtproto/TL-tl#remarks. func (*ChatRevenueStatistics) TypeID() uint32 { return ChatRevenueStatisticsTypeID } // TypeName returns name of type in TL schema. func (*ChatRevenueStatistics) TypeName() string { return "chatRevenueStatistics" } // TypeInfo returns info about TL type. func (c *ChatRevenueStatistics) TypeInfo() tdp.Type { typ := tdp.Type{ Name: "chatRevenueStatistics", ID: ChatRevenueStatisticsTypeID, } if c == nil { typ.Null = true return typ } typ.Fields = []tdp.Field{ { Name: "RevenueByHourGraph", SchemaName: "revenue_by_hour_graph", }, { Name: "RevenueGraph", SchemaName: "revenue_graph", }, { Name: "RevenueAmount", SchemaName: "revenue_amount", }, { Name: "UsdRate", SchemaName: "usd_rate", }, } return typ } // Encode implements bin.Encoder. func (c *ChatRevenueStatistics) Encode(b *bin.Buffer) error { if c == nil { return fmt.Errorf("can't encode chatRevenueStatistics#636318bb as nil") } b.PutID(ChatRevenueStatisticsTypeID) return c.EncodeBare(b) } // EncodeBare implements bin.BareEncoder. func (c *ChatRevenueStatistics) EncodeBare(b *bin.Buffer) error { if c == nil { return fmt.Errorf("can't encode chatRevenueStatistics#636318bb as nil") } if c.RevenueByHourGraph == nil { return fmt.Errorf("unable to encode chatRevenueStatistics#636318bb: field revenue_by_hour_graph is nil") } if err := c.RevenueByHourGraph.Encode(b); err != nil { return fmt.Errorf("unable to encode chatRevenueStatistics#636318bb: field revenue_by_hour_graph: %w", err) } if c.RevenueGraph == nil { return fmt.Errorf("unable to encode chatRevenueStatistics#636318bb: field revenue_graph is nil") } if err := c.RevenueGraph.Encode(b); err != nil { return fmt.Errorf("unable to encode chatRevenueStatistics#636318bb: field revenue_graph: %w", err) } if err := c.RevenueAmount.Encode(b); err != nil { return fmt.Errorf("unable to encode chatRevenueStatistics#636318bb: field revenue_amount: %w", err) } b.PutDouble(c.UsdRate) return nil } // Decode implements bin.Decoder. func (c *ChatRevenueStatistics) Decode(b *bin.Buffer) error { if c == nil { return fmt.Errorf("can't decode chatRevenueStatistics#636318bb to nil") } if err := b.ConsumeID(ChatRevenueStatisticsTypeID); err != nil { return fmt.Errorf("unable to decode chatRevenueStatistics#636318bb: %w", err) } return c.DecodeBare(b) } // DecodeBare implements bin.BareDecoder. func (c *ChatRevenueStatistics) DecodeBare(b *bin.Buffer) error { if c == nil { return fmt.Errorf("can't decode chatRevenueStatistics#636318bb to nil") } { value, err := DecodeStatisticalGraph(b) if err != nil { return fmt.Errorf("unable to decode chatRevenueStatistics#636318bb: field revenue_by_hour_graph: %w", err) } c.RevenueByHourGraph = value } { value, err := DecodeStatisticalGraph(b) if err != nil { return fmt.Errorf("unable to decode chatRevenueStatistics#636318bb: field revenue_graph: %w", err) } c.RevenueGraph = value } { if err := c.RevenueAmount.Decode(b); err != nil { return fmt.Errorf("unable to decode chatRevenueStatistics#636318bb: field revenue_amount: %w", err) } } { value, err := b.Double() if err != nil { return fmt.Errorf("unable to decode chatRevenueStatistics#636318bb: field usd_rate: %w", err) } c.UsdRate = value } return nil } // EncodeTDLibJSON implements tdjson.TDLibEncoder. func (c *ChatRevenueStatistics) EncodeTDLibJSON(b tdjson.Encoder) error { if c == nil { return fmt.Errorf("can't encode chatRevenueStatistics#636318bb as nil") } b.ObjStart() b.PutID("chatRevenueStatistics") b.Comma() b.FieldStart("revenue_by_hour_graph") if c.RevenueByHourGraph == nil { return fmt.Errorf("unable to encode chatRevenueStatistics#636318bb: field revenue_by_hour_graph is nil") } if err := c.RevenueByHourGraph.EncodeTDLibJSON(b); err != nil { return fmt.Errorf("unable to encode chatRevenueStatistics#636318bb: field revenue_by_hour_graph: %w", err) } b.Comma() b.FieldStart("revenue_graph") if c.RevenueGraph == nil { return fmt.Errorf("unable to encode chatRevenueStatistics#636318bb: field revenue_graph is nil") } if err := c.RevenueGraph.EncodeTDLibJSON(b); err != nil { return fmt.Errorf("unable to encode chatRevenueStatistics#636318bb: field revenue_graph: %w", err) } b.Comma() b.FieldStart("revenue_amount") if err := c.RevenueAmount.EncodeTDLibJSON(b); err != nil { return fmt.Errorf("unable to encode chatRevenueStatistics#636318bb: field revenue_amount: %w", err) } b.Comma() b.FieldStart("usd_rate") b.PutDouble(c.UsdRate) b.Comma() b.StripComma() b.ObjEnd() return nil } // DecodeTDLibJSON implements tdjson.TDLibDecoder. func (c *ChatRevenueStatistics) DecodeTDLibJSON(b tdjson.Decoder) error { if c == nil { return fmt.Errorf("can't decode chatRevenueStatistics#636318bb to nil") } return b.Obj(func(b tdjson.Decoder, key []byte) error { switch string(key) { case tdjson.TypeField: if err := b.ConsumeID("chatRevenueStatistics"); err != nil { return fmt.Errorf("unable to decode chatRevenueStatistics#636318bb: %w", err) } case "revenue_by_hour_graph": value, err := DecodeTDLibJSONStatisticalGraph(b) if err != nil { return fmt.Errorf("unable to decode chatRevenueStatistics#636318bb: field revenue_by_hour_graph: %w", err) } c.RevenueByHourGraph = value case "revenue_graph": value, err := DecodeTDLibJSONStatisticalGraph(b) if err != nil { return fmt.Errorf("unable to decode chatRevenueStatistics#636318bb: field revenue_graph: %w", err) } c.RevenueGraph = value case "revenue_amount": if err := c.RevenueAmount.DecodeTDLibJSON(b); err != nil { return fmt.Errorf("unable to decode chatRevenueStatistics#636318bb: field revenue_amount: %w", err) } case "usd_rate": value, err := b.Double() if err != nil { return fmt.Errorf("unable to decode chatRevenueStatistics#636318bb: field usd_rate: %w", err) } c.UsdRate = value default: return b.Skip() } return nil }) } // GetRevenueByHourGraph returns value of RevenueByHourGraph field. func (c *ChatRevenueStatistics) GetRevenueByHourGraph() (value StatisticalGraphClass) { if c == nil { return } return c.RevenueByHourGraph } // GetRevenueGraph returns value of RevenueGraph field. func (c *ChatRevenueStatistics) GetRevenueGraph() (value StatisticalGraphClass) { if c == nil { return } return c.RevenueGraph } // GetRevenueAmount returns value of RevenueAmount field. func (c *ChatRevenueStatistics) GetRevenueAmount() (value ChatRevenueAmount) { if c == nil { return } return c.RevenueAmount } // GetUsdRate returns value of UsdRate field. func (c *ChatRevenueStatistics) GetUsdRate() (value float64) { if c == nil { return } return c.UsdRate }