package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
var (
_ = bin .Buffer {}
_ = context .Background ()
_ = fmt .Stringer (nil )
_ = strings .Builder {}
_ = errors .Is
_ = multierr .AppendInto
_ = sort .Ints
_ = tdp .Format
_ = tgerr .Error {}
_ = tdjson .Encoder {}
)
type BusinessWorkHours struct {
Flags bin .Fields
OpenNow bool
TimezoneID string
WeeklyOpen []BusinessWeeklyOpen
}
const BusinessWorkHoursTypeID = 0x8c92b098
var (
_ bin .Encoder = &BusinessWorkHours {}
_ bin .Decoder = &BusinessWorkHours {}
_ bin .BareEncoder = &BusinessWorkHours {}
_ bin .BareDecoder = &BusinessWorkHours {}
)
func (b *BusinessWorkHours ) Zero () bool {
if b == nil {
return true
}
if !(b .Flags .Zero ()) {
return false
}
if !(b .OpenNow == false ) {
return false
}
if !(b .TimezoneID == "" ) {
return false
}
if !(b .WeeklyOpen == nil ) {
return false
}
return true
}
func (b *BusinessWorkHours ) String () string {
if b == nil {
return "BusinessWorkHours(nil)"
}
type Alias BusinessWorkHours
return fmt .Sprintf ("BusinessWorkHours%+v" , Alias (*b ))
}
func (b *BusinessWorkHours ) FillFrom (from interface {
GetOpenNow () (value bool )
GetTimezoneID () (value string )
GetWeeklyOpen () (value []BusinessWeeklyOpen )
}) {
b .OpenNow = from .GetOpenNow ()
b .TimezoneID = from .GetTimezoneID ()
b .WeeklyOpen = from .GetWeeklyOpen ()
}
func (*BusinessWorkHours ) TypeID () uint32 {
return BusinessWorkHoursTypeID
}
func (*BusinessWorkHours ) TypeName () string {
return "businessWorkHours"
}
func (b *BusinessWorkHours ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "businessWorkHours" ,
ID : BusinessWorkHoursTypeID ,
}
if b == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "OpenNow" ,
SchemaName : "open_now" ,
Null : !b .Flags .Has (0 ),
},
{
Name : "TimezoneID" ,
SchemaName : "timezone_id" ,
},
{
Name : "WeeklyOpen" ,
SchemaName : "weekly_open" ,
},
}
return typ
}
func (b *BusinessWorkHours ) SetFlags () {
if !(b .OpenNow == false ) {
b .Flags .Set (0 )
}
}
func (b *BusinessWorkHours ) Encode (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("can't encode businessWorkHours#8c92b098 as nil" )
}
buf .PutID (BusinessWorkHoursTypeID )
return b .EncodeBare (buf )
}
func (b *BusinessWorkHours ) EncodeBare (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("can't encode businessWorkHours#8c92b098 as nil" )
}
b .SetFlags ()
if err := b .Flags .Encode (buf ); err != nil {
return fmt .Errorf ("unable to encode businessWorkHours#8c92b098: field flags: %w" , err )
}
buf .PutString (b .TimezoneID )
buf .PutVectorHeader (len (b .WeeklyOpen ))
for idx , v := range b .WeeklyOpen {
if err := v .Encode (buf ); err != nil {
return fmt .Errorf ("unable to encode businessWorkHours#8c92b098: field weekly_open element with index %d: %w" , idx , err )
}
}
return nil
}
func (b *BusinessWorkHours ) Decode (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("can't decode businessWorkHours#8c92b098 to nil" )
}
if err := buf .ConsumeID (BusinessWorkHoursTypeID ); err != nil {
return fmt .Errorf ("unable to decode businessWorkHours#8c92b098: %w" , err )
}
return b .DecodeBare (buf )
}
func (b *BusinessWorkHours ) DecodeBare (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("can't decode businessWorkHours#8c92b098 to nil" )
}
{
if err := b .Flags .Decode (buf ); err != nil {
return fmt .Errorf ("unable to decode businessWorkHours#8c92b098: field flags: %w" , err )
}
}
b .OpenNow = b .Flags .Has (0 )
{
value , err := buf .String ()
if err != nil {
return fmt .Errorf ("unable to decode businessWorkHours#8c92b098: field timezone_id: %w" , err )
}
b .TimezoneID = value
}
{
headerLen , err := buf .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode businessWorkHours#8c92b098: field weekly_open: %w" , err )
}
if headerLen > 0 {
b .WeeklyOpen = make ([]BusinessWeeklyOpen , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
var value BusinessWeeklyOpen
if err := value .Decode (buf ); err != nil {
return fmt .Errorf ("unable to decode businessWorkHours#8c92b098: field weekly_open: %w" , err )
}
b .WeeklyOpen = append (b .WeeklyOpen , value )
}
}
return nil
}
func (b *BusinessWorkHours ) SetOpenNow (value bool ) {
if value {
b .Flags .Set (0 )
b .OpenNow = true
} else {
b .Flags .Unset (0 )
b .OpenNow = false
}
}
func (b *BusinessWorkHours ) GetOpenNow () (value bool ) {
if b == nil {
return
}
return b .Flags .Has (0 )
}
func (b *BusinessWorkHours ) GetTimezoneID () (value string ) {
if b == nil {
return
}
return b .TimezoneID
}
func (b *BusinessWorkHours ) GetWeeklyOpen () (value []BusinessWeeklyOpen ) {
if b == nil {
return
}
return b .WeeklyOpen
}
The pages are generated with Golds v0.8.4 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .